Can't seem to run a program from a service. Any ideas why?
I made a small service program that is starting as SYSTEM. In it I need to open a file. I'm using the following line that works perfectly fine in a regular Win32 app:
but when I run it from my service the return code is greater than 32 (meaning success), and I can see calc.exe in the task manager but there's nothing on the screen.
Re: Can't seem to run a program from a service. Any ideas why?
Originally Posted by Skizmo
Yes. Read the documentation on services and you will see that there is a option you can use to make service visible.
I don't really need an interactive service, I'm just trying to start a "regular" (non-service) process from my service and I want it to show on the desktop for user input.
Re: Can't seem to run a program from a service. Any ideas why?
Originally Posted by ahmd
Thanks, Arjay.
More than 500 lines of code just to run a program + additional hundred in the comments to clean up the result, come on, man
Well considering you are in a different desktop and have to find the correct desktop for the user, is it really that bad?
Let me get this straight, are you complaining because there are lots of comments?
You know of course that you aren't suppose to just cut & paste the msdn snippets into your source code, right? (because nothing says "amateur" more than running across source code that is an obvious cut and paste job).
Re: Can't seem to run a program from a service. Any ideas why?
Well, I just killed 4 hours trying to make this sample work. For some stupid reason the CreateProcessAsUser was throwing an exception from within and I couldn't figure out why. It took me several times to reread their documentation to see that this API may modify the lpCommandLine parameter in a unicode build and it cannot be const like they put it in their dumb sample. There must have been a bunch of "professionals" at Microsoft who wrote it. Good point Arjay...
Re: Can't seem to run a program from a service. Any ideas why?
Originally Posted by ahmd
Well, I just killed 4 hours trying to make this sample work. For some stupid reason the CreateProcessAsUser was throwing an exception from within and I couldn't figure out why. It took me several times to reread their documentation to see that this API may modify the lpCommandLine parameter in a unicode build and it cannot be const like they put it in their dumb sample. There must have been a bunch of "professionals" at Microsoft who wrote it. Good point Arjay...
This is part of the learning curve. No sample is perfect, but there's no need to blame Microsoft.
Btw, you can be part of the solution by pointing out the error in the sample documentation. You'll notice that at the bottom of the documentation there is a place where you can send feedback to Microsoft. You just might get it fixed for the next guy.
Bookmarks