|
-
May 9th, 2005, 03:00 PM
#1
Thread Starter
Member
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:
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???
-
May 9th, 2005, 03:16 PM
#2
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")
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 10th, 2013, 12:01 PM
#3
Re: Shell function - "File Not Found"
Thanks!
 I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
My war with a browser-redirect trojan
-
May 10th, 2013, 12:11 PM
#4
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!!!!
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 10th, 2013, 12:35 PM
#5
Re: Shell function - "File Not Found"
I think he's probably got that figured out by now.
 I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
My war with a browser-redirect trojan
-
May 10th, 2013, 12:49 PM
#6
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!
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 10th, 2013, 12:51 PM
#7
Re: Shell function - "File Not Found"
 I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
My war with a browser-redirect trojan
-
Nov 7th, 2014, 05:52 PM
#8
New Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|