[.net] how to load .bat file with VC#.net

Started by
1 comment, last by Rob Loach 18 years, 9 months ago
I need to make a button to load my .bat file when i click it. i tried to use this ....... System.Diagnostics.Process.Start("my_program.exe"); But it can load only .exe file. so i need to ask.... 1.What 'System.Diagnostics.Process.Start()' do for us? 2.How to load .bat file
Advertisement
1. It does interop to the CreateProcess function.
2. Normally "Process.Start(@"c:\temp\a.bat");" should work. Possibly antivirus, or antispyware software could prevent this from work.

As an alternative you could try something like this:

string commandProcessor = Environment.GetEnvironmentVariable("COMSPEC");
Process process = Process.Start(commandProcessor, @"/c c:\temp\a.cmd");
process.WaitForExit();
As an alternative, you could use the Window's shell directly via ShellExecute:

[DllImport("shell32.dll")]public static extern int ShellExecute(    int hwnd, string lpOperation,    string lpFile, string lpParams,    string lpDir, int lpShowCmd);ShellExecute(0, "open", filename, "", "", 1);
Rob Loach [Website] [Projects] [Contact]

This topic is closed to new replies.

Advertisement