|
-
Feb 8th, 2012, 08:43 PM
#1
Thread Starter
Member
Process.Start - Set Start In Directory
Good evening. I am writing an application that in the end needs to execute another executable at some point, the problem is that the executable has dependencies in the directory it runs in that are required to operate. When I use the Process.Start to run the executable it errors out because it's looking for the dependencies in my applications directory.
I tried the startInfo.WorkingDirectory option but that didn't seem to do it either (not sure if I did it right) - here is how I used that:
Process.Start("my.exe").StartInfo.WorkingDirectory = "C:\Test"
For the life of me I cannot find how to set the "Start In" directory. I looked everywhere, so unless it's under a different name, I'm at a loss.
Any help is appreciated!
-
Feb 8th, 2012, 09:04 PM
#2
Re: Process.Start - Set Start In Directory
You can't set the start info after the process has started. Create a ProcessStartInfo object first, set the appropriate properties and then pass that object as an argument when you call Process.Start.
-
Feb 8th, 2012, 09:08 PM
#3
Thread Starter
Member
Re: Process.Start - Set Start In Directory
 Originally Posted by jmcilhinney
You can't set the start info after the process has started. Create a ProcessStartInfo object first, set the appropriate properties and then pass that object as an argument when you call Process.Start.
Oh geez - it was that easy! I knew I was wrong somewhere in the use of the WorkingDirectory setup. Thanks I really appreciate it. For those who might (I doubt) have the same problem, the code to fix it was:
Dim ClientStartup As New ProcessStartInfo("yourexe.exe")
ClientStartup.WorkingDirectory = "C:\YourDirectory"
Process.Start(ClientStartup).WaitForExit()
Thanks again.
-
Feb 8th, 2012, 11:46 PM
#4
Re: Process.Start - Set Start In Directory
If you're using VB 2008 or later then you can use initialiser syntax to condense that to:
Code:
Process.Start(New ProcessStartInfo("file path here") With {.WorkingDirectory = "folder path here"}).WaitForExit()
Note also that, while it may not be, the working directory will usually be the folder containing the EXE, so you can do this:
Code:
Dim filePath As String 'Store file path here.
Process.Start(New ProcessStartInfo(filePath) With {.WorkingDirectory = IO.Path.GetDirectoryName(filePath)}).WaitForExit()
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
|