Shell function - "File Not Found"
I think this should be a simple mistake but I can't figure out where I'm going wrong. Thanks in advance for any suggestions.
I'm having a problem using the Shell() function in my VB.NET code. I had it working a couple of months ago and went back to add some comments to my code, recompiled, and now it get the following error:
Quote:
Unhandled Exception: System.IO.FileNotFoundException: File not found.
at Microsoft.VisualBasic.Interaction.Shell(String Pathname, AppWinStyle Style, Boolean Wait, Int32 Timeout)
at RunFileProcessing.RunFileProcessing.Main()
My code is this:
VB Code:
Shell("dir")
' -or-
Microsoft.VisualBasic.Interaction.Shell("dir")
'Shell("C:\Autosys45\Utilities\cawto.bat" & """" & OutputMessage & """")
' -or-
'Microsoft.VisualBasic.Interaction.Shell("C:\Autosys45\Utilities\cawto.bat" & """" & OutputMessage & """")
I'm trying to call the .bat file listed but I get the error above. But if I change it to just do a simple "dir" I still get the same error. I've made sure I added a reference to Microsoft.VisualBasic.Vsa and I've tried using the following Imports at the top of the vb:
VB Code:
Imports Microsoft.VisualBasic
' -or-
Imports Microsoft.VisualBasic.Interaction
My program throws the error no matter what I do unless I just comment out the lines where I use "Shell". Does anyone have any idea what I could be doing wrong? Is there another way to execute a batch file in VB.NET???
Re: Shell function - "File Not Found"
Your better off using the .NET method of Process.Start.
VB Code:
Dim oProcess As Process
oProcess.Start("Notepad.exe")
Re: Shell function - "File Not Found"
Re: Shell function - "File Not Found"
Er yeah but you're going to get exactly the same error if you continue to leave out the required space between the filename and the parameters!!!!
Re: Shell function - "File Not Found"
I think he's probably got that figured out by now. ;)
Re: Shell function - "File Not Found"
Oh right. Didn't notice the date! Mind you, it's only been 8 years .... you just never know!
Re: Shell function - "File Not Found"
Re: Shell function - "File Not Found"
Sorry for the thread bump, but this is a popular topic found on Google and i wanted to chime in.
Shell() is significantly more reliable than .NET's Process.Start() method. On many machines with viruses where you cannot run .exes (due to hijacks), shell will run them perfectly. Further more, shell can be used to run/open many things, and in the cases of executable will return the PID which you can use to create a Process object, just as if you ran it with Process.Start().
At least, this is my experience. Ever since i saw Process.Start() fail, i use shell for everything.