Jump to content
  • Advertisement
Sign in to follow this  
bug_aonz

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

This topic is 4819 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!