Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Wednesday, June 9, 2010 11:08 PM
Start("Program.exe")
This does not work
Nor thisSystem.Diagnostics.Process.Start("Program.exe")
Only this works...but I can't use the Drive path..cannot hardcode it.
System.Diagnostics.Process.Start("C:\Program Files\X-Program\Program.exe")
So how do I start an outside Exe file from within vb net without hardcoding the path.
Vb net 2008
All replies (9)
Thursday, June 10, 2010 1:36 AM âś…Answered
I just tried
System.Diagnostics.Process.Start(String.Format("{0}\WinRAR\winrar.exe", Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)))
The application is on the desktop and it launched winrar.
Wednesday, June 9, 2010 11:16 PM | 1 vote
Is program.exe a companion program to one you are distributing? If so, just place it in the same directory as your application, and the Process.Start("program.exe") should find it. If it is an application you expect your user to have, such as MS Word for example, then there are other ways to start it possibly. Otherwise, yes, you need the full path.
--
Mike
Wednesday, June 9, 2010 11:34 PM
> So how do I start an outside Exe file from within vb net
> without hardcoding the path.
Google for the LoadLibrary search path. This is the order used by the
system to find executables as well.
In a nutshell, if the application is not in one of those six(?)
locations, your only option is to:
* Find it
* Make that folder the current directory, or
Build the full pathspec before executing it.
Make sense?
.NET: It's About Trust!
http://vfred.mvps.org
Thursday, June 10, 2010 12:08 AM
Hi mindserve,
Another option is to have the user select the location and the filename of the EXE
file that you wish to run using an OpenFileDialog. If this is a viable option for you
then I can post an example.
Otherwise please try as forum user Family Tree Mike says and put the EXE file in the same folder as your program.
During development your program will compile to the Bin\Debug or the Bin\Release folder
( depending on a compiler setting ) within the PROJECTS\YourProjectNameHere\YourProjectNameHere\ folder.
For example my projects are in the following default locations on my computer.>>
C:\Users\John\Documents\Visual Studio 2005\Projects\
C:\Users\John\Documents\Visual Studio 2008\Projects\
C:\Users\John\Documents\Visual Studio 2010\Projects\
which is the location for your projects if you are using Windows 7.
Use the one that suits the version - year of Vb.Net that you are using. :-) ;-)
Replace John with your user name on your computer.
Have a look in your Documents or MyDocuments folder if you are not using Windows 7.
Here is an example of the full path to where the EXE for a particular project is created on my computer.>>
C:\Users\John\Documents\Visual Studio 2008\Projects\Counting_Sorted_Lists\Counting_Sorted_Lists\bin\Debug\
If your other program is in the same folder as your program try using these lines in your code.>>
Dim programName As String = "myOtherProgram.exe"
System.Diagnostics.Process.Start(Application.StartupPath & "\" & programName)
Application.Startup should always point to the location your
program is installed in regardless of where it is on any computer. :-D
Regards,
John
Thursday, June 10, 2010 12:34 AM
Asking the user would be just another way to "find it" as I suggested.
(Probably *the* tackiest way, but that's a side issue I suppose.)
I don't see the need to put the file anywhere in particular, either.
All that matters is you know where it is. You can then simply
construct the full pathspec to launch it, or (perhaps better for some
situations) change the current working directory to that folder, launch
it, then change back to the prior working directory.
.NET: It's About Trust!
http://vfred.mvps.org
Thursday, June 10, 2010 12:45 AM
The path would always be in the program files path but it's not something I am distributing so it is not in the application path.
System.Diagnostics.Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) &
"\ & "ExternalNotMine.exe")
I thought the above might work, but so far nothing.
Looking at loadlibrary......not many vb net examples.
Thursday, June 10, 2010 12:58 AM
Using the following code:
System.Diagnostics.Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) & "\ & "ExternalNotMine.exe")
That would assume that the executable was contained directly within the Program Files folder. Usually an application contains a subfolder within Program Files.
By the way, Path.Combine() is much better for combining directories and files together, as opposed to string concatenation. You don't need to worry about the missing or extra slashes.
--
Mike
Thursday, June 10, 2010 12:59 AM
Hi,
Did you try.>>
Application.StartupPath
?
Regards,
John
Thursday, June 10, 2010 9:57 AM
That worked!!!!!!!!!!!!!!! Thanks.