Link to home
Start Free TrialLog in
Avatar of casit
casitFlag for United States of America

asked on

How to execute .bat from C# service?

Hello I have a C# service that I have created.  Inside the .exe after doing certain things I need to be able to execute a .bat file.  
I don't have to worry about Input, Output or anything.

Currently I'm using the following and its not working.
Avatar of Randy Downs
Randy Downs
Flag of United States of America image

try this

http://stackoverflow.com/questions/361097/c-sharp-service-cannot-execute-batch-file

proc.StartInfo.FileName                 = target;            
proc.StartInfo.RedirectStandardError    = true;            
proc.StartInfo.RedirectStandardOutput   = true;            
proc.StartInfo.UseShellExecute          = false;              
proc.Start();              
proc.WaitForExit                
(                    
(timeout <= 0)                    
? int.MaxValue : timeout * NO_MILLISECONDS_IN_A_SECOND *                        NO_SECONDS_IN_A_MINUTE                
);              
errorMessage    = proc.StandardError.ReadToEnd();            
proc.WaitForExit();              
outputMessage   = proc.StandardOutput.ReadToEnd();            
proc.WaitForExit();
Avatar of casit

ASKER

nope didn't work.
Maybe you could duplicate the actions of the .bat with C#
Avatar of casit

ASKER

no because the .bat executes a literall program.
Can we see your code ur trying to execute the batch file from the service ? Also the error / other details will be good.

Are you running the service with sufficient privileges to run a .bat file insider?
ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial