Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have one problem for running batch files using c#.

If I am running manually batch file is running with C:\Windows\System32\cmd.exe (Command Prompt), Incase I am using through c# batch file is running with C:\Windows\SysWOW64\cmd.exe (Windows Command Processor).

I need to run my batch file forcefully to C:\Windows\System32\cmd.exe only.

Can u help any one on this.

Regard's
Surendra Reddy.
Posted

1 solution

Try giving full path instead of just "cmd.exe".
%windir%\System32\cmd.exe /c yourbatchFile.bat


Hope, it helps :)
 
Share this answer
 
Comments
Surendra Reddy V 6-Aug-15 2:20am    
Hi Shekhar,

I am using like below which is u suggested its throwing error:
Process.Start(@"%windir%\System32\cmd.exe" , @"/c call D:\PROJECTS\LDB Source\Stocks LDB\Paint.bat");

Error:

"The system cannot find the file specified"

Regard's
Surendra.
Suvendu Shekhar Giri 6-Aug-15 2:30am    
It should be there. Type %windir%\System32\cmd.exe in Run (press Windows key + R) and check whether command prompt is opening or not.
Maciej Los 6-Aug-15 2:45am    
Try to add extra "" around the path to the .bat file. Command prompt does not accept spaces in a path, so it stop reading the command here: D:\Projects\LDB and ignores the rest of command.
Process.Start(@"%windir%\System32\cmd.exe" , @"'/c call D:\PROJECTS\LDB Source\Stocks LDB\Paint.bat'"); - would do the trick ;)
Surendra Reddy V 6-Aug-15 2:58am    
Hi Los,

I tried which u suggested , but same error . even if I am changing directory also same error.
Process.Start(@"%windir%\System32\cmd.exe", @"'/c call C:\PROJECTS\Paint.bat'");
Maciej Los 6-Aug-15 3:01am    
So, add double quotes instead of single qoutes.
Process.Start(@"%windir%\System32\cmd.exe" , @"""/c call D:\PROJECTS\LDB Source\Stocks LDB\Paint.bat""");

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900