Click here to Skip to main content
15,559,455 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want run .bat file once i received specific mail but now .bat file is not running through windows services.
When i run my program normally in Visual Studio then .bat file is running but it is not running through Windows Service. I have handled Exception but it is not giving me exception also. So i am not getting where is the problem.
I have try different way it is working in normal program but not working for windows service.

What I have tried:

Try 1:

Try 2:
string fileName = @"C:\Users\Pankaj.Joshi\Documents\UiPath\";
Process p = new Process();
p.StartInfo = new ProcessStartInfo(@"C:\Python36_64\python.exe", fileName)
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
string output = p.StandardOutput.ReadToEnd();
Updated 5-Dec-21 22:57pm
F-ES Sitecore 23-Nov-18 4:33am    
Attach the debugger to the service to get a better idea what is going on. It might not have access permissions to the py file, or python.exe might be doing something that doesn't work in a service.

As I mentioned in your original question on this subject, I do not think you can do this. A Windows service does not have a console, so it cannot use stdin or stdout.
Share this answer
This is NOT going to work. You're entire service app is flawed by design.

First, you cannot use Outlook from a service application. Interaction with ANY Office app is not supported when done from an unattended session, like a Windows Service.

Second, the service is running as a different account that will NOT have access to your email accounts in Outlook.

This app should NOT be a service at all. This should be an application that runs only when you're logged in AND the app is running as you. You can solve the first problem by converting this code back to a normal application and launching it out of the Run key in the registry.

The second problem is solved automatically because the Run key is a just a list of applications that are automatically launched as the user that just logged into Windows.

Oh, and you answer your question why the batch doesn't get executed, the code that kicks it off never gets called probably because some condition you set to kick it off is never met, like receiving an email it can never see.
Share this answer
Member 13156238 26-Nov-18 3:21am    
Thanks Dave Kreskowiak,
Thanks for your comment its really helpful.
So i need to create normal program and its lunch it out of the Run key in the registry.
So i can run my program (Program is read mail and Run.bat file) from this. am i right ????
Dave Kreskowiak 26-Nov-18 9:09am    
Member 15456994 6-Dec-21 5:15am    
I am facing the same issue as this and the above solution is not working for me. When I run my program normally in Visual Studio then .bat file is running but it is not running through Windows Service. I am just calling a simple batch file(to test)which launches a command prompt window. I tried calling .py file in my code and it works fine with windows service too (WHY SO?). Also, when a configure my program.exe as a schedule task , it works fine. But for some reason. .bat file does not triggers from windows service. Seems I am missing something silly here. Pls suggest. @Dave Kreskowiak
Dave Kreskowiak 6-Dec-21 10:39am    
Go to the "Quick Answers" menu and click "Ask a question". Don't hijack an old question with yours.

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