简体   繁体   中英

Process.Start() does nothing when called from a C# written service

I have created a service that works good, except for this section that don't do what I want

shutdownProcess.StartInfo.RedirectStandardError = true;
shutdownProcess.StartInfo.WorkingDirectory = @"C:\Program Files (x86)\Siemens\Automation\WinCC RT Advanced";
shutdownProcess.StartInfo.FileName = @"C:\Program Files (x86)\Siemens\Automation\HmiRtmShutdown.exe";
shutdownProcess.Start();

string errors = shutdownProcess.StandardError.ReadToEnd();
eventLog1.WriteEntry(errors, EventLogEntryType.Error, eventId++);

The problem is that the process is not executed; as you can see I tried to record errors in a log, but the log records a empty string so it seems that there is no error;

This application works perfectly when I call it from cmd.exe; I also tried to use process.start() with cmd.exe passing the path as argument, but it did not work; I installed the service as LocalSystem to give it maximum privileges; I also tried to put the service into same folder and call only the .exe to exclude errors in writing the path; nothing

please help!

You cannot execute applications or executables which try to render a User Interface or are designed to require interactive login from a Windows Service which runs in background in UI less mode ( Session 0 from Vista onwards as others have comemnted ).

try to wite some unit tests and run your code from the unit tests in Visual Studio, if all works fine but then from the Windows Service does not work, then the problem is exactly the one explained above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM