|
-
July 6th, 2005, 01:17 AM
#1
Opening an .exe file
How can I open another .exe file from my vb.net application?
-
July 6th, 2005, 01:54 AM
#2
Re: Opening an .exe file
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")
-
July 6th, 2005, 02:56 AM
#3
Re: Opening an .exe file
In VB.NET you have the Shell function.
For example (from MSDN)
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("=")
It is found in Microdsoft.VisualBasic namespace.
-
July 6th, 2005, 12:16 PM
#4
Re: Opening an .exe file
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.
-
July 9th, 2005, 06:55 AM
#5
Re: Opening an .exe file
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
-
July 9th, 2005, 12:14 PM
#6
Re: Opening an .exe file
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.
-
July 10th, 2005, 02:28 AM
#7
Re: Opening an .exe 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.
-
July 11th, 2005, 01:59 PM
#8
Re: Opening an .exe file
Are you escaping the \ in the filepath ? Or putting an @ at the start of the string that houses the path?
-
July 15th, 2005, 02:14 AM
#9
Re: Opening an .exe file
I am not escaping or adding such characters.
-
July 15th, 2005, 03:18 AM
#10
Re: Opening an .exe file
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.
-
July 17th, 2005, 04:29 AM
#11
Re: Opening an .exe file
 Originally Posted by vb_the_best
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")
This code does not work..and gives the error file not found,although the file is there.
-
July 17th, 2005, 05:03 AM
#12
Re: Opening an .exe file
 Originally Posted by SoftLock
This code does not work
It worked on my computer on an exe located on C:\ .
There is nothing wrong with the code vb_the_best gave.
.NET can't find your exe.
-
July 17th, 2005, 10:12 AM
#13
Re: Opening an .exe file
 Originally Posted by SoftLock
This code does not work..and gives the error file not found,although the file is there.
As jhammer has already posted, it works perfectly on my system too...
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...
-
July 17th, 2005, 01:03 PM
#14
Re: Opening an .exe file
-
July 23rd, 2005, 06:28 AM
#15
Re: Opening an .exe file
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.
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
|