-
August 4th, 2009, 06:40 PM
#1
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:
Code:
ShellExecute(NULL, _T(""), _T("calc.exe"), _T(""), _T(""), SW_SHOW);
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.
What am I not doing right?
-
August 4th, 2009, 06:44 PM
#2
Re: Can't seem to run a program from a service. Any ideas why?
The service runs under a different desktop. The program is starting and is running on a desktop it just isn't the same desktop as a logged on user.
-
August 5th, 2009, 02:15 AM
#3
Re: Can't seem to run a program from a service. Any ideas why?
Thanks, Arjay. It makes sense. But, is it possinle to run that file in a current desktop from my service?
-
August 5th, 2009, 02:18 AM
#4
Re: Can't seem to run a program from a service. Any ideas why?
Originally Posted by ahmd
Thanks, Arjay. It makes sense. But, is it possinle to run that file in a current desktop from my service?
Yes. Read the documentation on services and you will see that there is a option you can use to make service visible.
-
August 5th, 2009, 10:30 AM
#5
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.
That no longer works or is recommended on Vista and above.
-
August 5th, 2009, 08:59 PM
#6
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.
Guys, I found this sample on MSDN:
http://msdn.microsoft.com/en-us/libr...08(VS.85).aspx
It's kinda big and bulky (like anything else from Microsoft), so before I begin trying to tailor it, do you think is it what I need in my case?
-
August 5th, 2009, 09:05 PM
#7
Re: Can't seem to run a program from a service. Any ideas why?
Originally Posted by ahmd
It's kinda big and bulky (like anything else from Microsoft), so before I begin trying to tailor it, do you think is it what I need in my case?
It's what you need. Not sure about the big and bulky comment though.
-
August 5th, 2009, 09:22 PM
#8
Re: Can't seem to run a program from a service. Any ideas why?
Thanks, Arjay.
Originally Posted by Arjay
Not sure about the big and bulky comment though.
More than 500 lines of code just to run a program + additional hundred in the comments to clean up the result, come on, man
-
August 5th, 2009, 10:37 PM
#9
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).
-
August 6th, 2009, 01:53 AM
#10
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...
-
August 6th, 2009, 12:34 PM
#11
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|