0

I have written a windows service and i am calling one of my exe from this windows service.

new exe starting successfully ant getting stopped in 2-3 sec.

Can anyone suggest on it?

King
  • 16
  • 5
  • put some logging in application and see what is wrong! – Neel Jul 15 '15 at 13:57
  • new exe is running successfully. Its showing in task manager for few seconds. But its stopping automatically. – King Jul 15 '15 at 14:03
  • Add more info to your question. – robsch Jul 15 '15 at 14:04
  • 1
    We are calling one of my exe from windows service say blah.exe, i have used Process to start it. When service started it lauches that exe on server and executing only for few seconds only, not completing process. If i run the exe directly from file system its working fine, facing problem only when i launch it from windows service. – King Jul 15 '15 at 14:09

1 Answers1

1

Launching apps from a Windows service via Process.Start() is not supported by Microsoft. It can sometimes work, but as you have seen, it is not reliable. Process.Start() is intended for launching applications from "interactive" processes, while services are considered "batch" processes.

To launch an application from a service, you will need to use Win32 API calls. An example of code that can do this can be found in this answer. This answer may also provide some useful information.

Community
  • 1
  • 1
nateirvin
  • 1,173
  • 1
  • 10
  • 28
  • Well, that's not really precise! We successfully run headless applications (console applications with hidden console window) from Windows services. What you mean is that GUI interaction is not supported anymore. – Thorsten Dittmar Jul 15 '15 at 14:38
  • @ThorstenDittmar, because it's too long to repost in a comment, please follow the link to the first linked answer - it gives the information a Microsoft Support engineer once gave me about this topic. – nateirvin Jul 15 '15 at 14:40
  • I think the important part in the Microsoft quote you didn't highlight is *when credentials are specified*. If you don't, the process will just be run under the same user the service runs under. As I said, your answer is correct for the "Desktop interactive" option that existed before Vista. You can not run desktop interactive applications from a Windows service since Vista. Your answer is incomplete in that it doesn't mention that you **can** run non-interactive simple console applications. You can even control them using the input/output streams. – Thorsten Dittmar Jul 15 '15 at 14:56