Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

How to execute bat file, through c# .net windows service?

I have a bat file, I want to run bat file, when my windows service it will be start.

How could that possible.

Please help me.
Thanks
Ankit Agarwal.
Posted

Just provide it as a target of Process.Start:
C#
System.Diagnostics.Process.Start(@"C:\MyBatchFiles\MyBatch.bat");
 
Share this answer
 
Comments
[no name] 15-Feb-13 4:33am    
There is not my solved query.
Because my bat file path it's a application installation root directory.
Application.Startuppath in windows form application but windows service it's not possible, how it can be possible in windows service?
C# Process.Start[^]
System.Diagnostic.Process.Start-Process class[^]

C#
using System.Diagnostics;

class Program
{
    static void Main()
    {
    //
    // Use Process.Start here.
    //
    Process.Start("C:\Users\pant\Documents\myfile.bat");
    }
}
 
Share this answer
 
Comments
sundar sahukhala 24-Aug-14 4:29am    
thank u very much
Abhishek Pant 24-Aug-14 7:17am    
pleasure to help you.

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