How can I open another .exe file from my vb.net application?
Printable View
How can I open another .exe file from my vb.net application?
If you want to execute another EXE from within your VB.NET App, then you could use
Code:'Put this on top of the of the Code
Imports System.Diagnostics
'Put this at a place where you want to execute the Exe
Dim newProc As Process = New Process
newProc.Start("C:\another.EXE")
In VB.NET you have the Shell function.
For example (from MSDN)
It is found in Microdsoft.VisualBasic namespace.Code:Dim ProcID As Integer
' Start the Calculator application, and store the process id.
ProcID = Shell("CALC.EXE", AppWinStyle.NormalFocus)
' Activate the Calculator application.
AppActivate(ProcID)
SendKeys.SendWait("22")
SendKeys.SendWait("*")
SendKeys.SendWait("44")
SendKeys.SendWait("=")
Shell is part of the old Microsoft.VisualBasic namespace. Its not considered as .NET code since MS just added
some of the VB6 functions to help make the transition easier for vb6'ers.
Using the System.Diagnostics.Process namespace is the best solution. ;)
I am unable to start another exe by implementing both of above specified methods. I get the error of 'File nt Found' though the specified exe is present in directory C:\. I am unable to handle this exception though these methods work very fine if the specified file is 'CALC.EXE' or 'CMD.EXE' but the same code does not work if the specified file is any other executable e.g. "C:\TCPServer.exe", i get the following error, plzzzz help !
Unhandled Exception: System.IO.FileNotFoundException: File not found.
at Microsoft.VisualBasic.Interaction.Shell(String Pathname, AppWinStyle Style , Boolean Wait, Int32 Timeout) at newProcess.Module1.Main() in :\Documents and Settings\Tess\My Documents\Visual Studio Projects\newProcess\Module1.vb:line 10
Press any key to continue
You have two options:
1. Pass as an arguement the full path to the executable you want to run.
2. Add to the path environment variable the path to the executable.
I prefer the first solution, and you can also store the full path in a configuration file.
Giving the whole path of the executable as an argument is not working as i explained before about the unhandled exception i am receiving. About the 2nd option, can you plz guide me how do we add it as environment variable. Please Help, thankyou.
Are you escaping the \ in the filepath ? Or putting an @ at the start of the string that houses the path?
I am not escaping or adding such characters.
In order to add the path to the Path environment variable:
Right click on My Computer, and select Properties.
Go to "Advanced" tab, and click on "Environment Variable".
On the top list find the Path variable and click on it.
Add the path(only folder) to the end of the path (seperating with ; char)
Click Ok twice.
You will need to close all instances of Visual Studio for the changes to take affect.
When you call from code simply give the executable name (without full path).
If this still doesn't work, remove from path, and try the bottom list of Environment Variable (the System ones).
If this still doesn't work, I strongly suggest you check if you spell the executable correctly, and the full path, and that the file is actually there, and remove any file properties (like readonly).
Hope this helps.
This code does not work..and gives the error file not found,although the file is there.Quote:
Originally Posted by vb_the_best
It worked on my computer on an exe located on C:\ .Quote:
Originally Posted by SoftLock
There is nothing wrong with the code vb_the_best gave.
.NET can't find your exe.
As jhammer has already posted, it works perfectly on my system too...Quote:
Originally Posted by SoftLock
Can you post the code you wrote, and make sure that the file you are trying o execute is present at the location you have given...
test kirim file vb code
thankyou all..infact the exe i was trying to open was named as "TCPServer.exe", and i just renamed the same exe and it got opened. the code worked perfectly fine. this was strange with that specific exe...neways, problem got solved, thnkyou all again for ur interest.