Kiran Sonawane
asked on
Execute batch file using windows service
I tried almost first 2 pages of google search with text "calling batch file from windows service". Still no luck. Also tried to edit registry of service (my service) as suggested in one of the link. My service is running under "Network services" account
Here is my sample code
Batch file code
Here is my sample code
private static void InvokeBatchFile()
{
using (System.Diagnostics.Process process = new System.Diagnostics.Process())
{
process.StartInfo.WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.System);
process.StartInfo = new System.Diagnostics.ProcessStartInfo(@"c:\windows\system32\cmd.exe");
process.StartInfo.FileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "cmd.exe");
process.StartInfo.Arguments = string.Format(@"/C C:\data\test.bat");
process.StartInfo.CreateNoWindow = true;
process.StartInfo.ErrorDialog = false;
process.StartInfo.UseShellExecute = false;
process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardInput = true;
process.Start();
}
}
Batch file code
echo "Batch file invoked" >> kiran.txt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Your solution doesn't help...
ASKER