Reputation: 13
I run my program and it works fine. I am using external Batch and VBS files however if these files are not in my main C:\ Directory then it don't work at all! I get a cannot find file specified and so How can I make sure that my files run in my directory that my program installs in every time C:\Program Files (x86)\ then of course it makes a program folder.
example of the code I used which I got from another forum on this site.
Process scriptProc = new Process();
scriptProc.StartInfo.FileName = @"Services.bat";
scriptProc.StartInfo.WorkingDirectory = @"c:\Program Files (x86)\Buzzard X Soy Optimzation Program\"; //<---very important
scriptProc.StartInfo.Arguments = "//B //Nologo Services.bat";
scriptProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; //prevent console window from popping up
scriptProc.Start();
scriptProc.WaitForExit();
scriptProc.Close();
Upvotes: 1
Views: 120
Reputation: 3291
You can use Environment.CurrentDirectory to get the directory from which your executeble was run, and navigate to the desired folder relative to your starting path.
You should virtually never put absolute paths in code, because of the exact problem you are encountering.
Upvotes: 1