Although one can run a batch file form c: location , i would like to know if its possible to have the .bat file inside the resources folder .
I tried this
Process p = new Process;
p.StartInfo.FileName = @"\Resources\batchfile.bat";
and this
p.StartInfo.FileName = @"\Resources\batchfile";
Both don't work .
Open Start. Search for Command Prompt, right-click the top result, and select the Run as administrator option. Type the following command to run a Windows 10 batch file and press Enter: C:\PATH\TO\FOLDER\BATCH-NAME. bat.
As SA told, use System. Diagnostics. Process namesapce to runout your batch file.
To fix this simply run the batch file, vsvars32. bat that comes with Visual Studio.NET from the command line in the working folder. After you run this batch file devenv.exe will be available from the command line in that folder.
string location;
Process p = new Process;
location = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location)
+@"\Resources\batchfile.bat";
p.StartInfo.FileName = location;
You can put a batch file in whatever file-system location you want.
It looks like the path to your batch file is wrong, though. Paths with a leading backslash are interpreted relative to the root directory of the current drive. That's probably not where your batch file is, though. It's probably in the Resources subdirectory of your application's own installation folder. At the very least, remove the leading backslashes from those strings. Then they will be interpreted relative to your process's current working directory.
It would be better to use a fully qualified path, though. The current working directory has a tendency to change when you're not expecting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With