Sign in to follow this  
bug_aonz

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

Recommended Posts

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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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();

Share this post


Link to post
Share on other sites
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);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this