Sheldon Livingston
asked on
Starting a program from a service in VB.NET
I created a service from vb.net 2005...
I would like to start an application... such as calc.exe.
calc.exe opens (I can see it task manager) but it isn't visible unless I change the service to interact with the desktop.
Anyone know any work arounds for this?
I would like to start an application... such as calc.exe.
calc.exe opens (I can see it task manager) but it isn't visible unless I change the service to interact with the desktop.
Anyone know any work arounds for this?
Hi,
I'll see what I can do to help you understand why you don't see calculator on the desktop. The service your running is most likely running under "SYSTEM" (LocalSystem) which means there is no desktop associated so calculator is launched in another session other than the session the user is running. If you look at task manager once more you will notice the calculator is running under the SYSTEM account.
There is some concern with using "interactive" option because this has all changed on Vista and later where you can't run interactive services so this option only works for XP and earlier and should be avoided.
If your service needs to run under SYSTEM then you have to use PInvoke and CreateProcessAsUser or CreateProcessWithToken. You must also be careful because if you don't specify an environment block for these calls there will be problems when the application use windows dialogs. If you know the application doesn't use dialogs like FileOpen, Print, FileSave then you can ignore the environment block. If the application your launching does use them or has GUI than it's best that you create the enviornment block.
I'll see what I can do to help you understand why you don't see calculator on the desktop. The service your running is most likely running under "SYSTEM" (LocalSystem) which means there is no desktop associated so calculator is launched in another session other than the session the user is running. If you look at task manager once more you will notice the calculator is running under the SYSTEM account.
There is some concern with using "interactive" option because this has all changed on Vista and later where you can't run interactive services so this option only works for XP and earlier and should be avoided.
If your service needs to run under SYSTEM then you have to use PInvoke and CreateProcessAsUser or CreateProcessWithToken. You must also be careful because if you don't specify an environment block for these calls there will be problems when the application use windows dialogs. If you know the application doesn't use dialogs like FileOpen, Print, FileSave then you can ignore the environment block. If the application your launching does use them or has GUI than it's best that you create the enviornment block.
ASKER
I understand why... just didn't know if there was a work around.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This is the type of thing that I am looking for...
Thank you
Thank you
NT Services do not have access to the interactive desktop by default.
Windows NT and above have the concept of window stations. Your logon session
has a window station and your service has its own. So they both have a
windows desktop of their own and you can only see yours. If your service
runs as local system you can use service control manager to give that
service access to the interactive desktop. So that might help but only for a
little while I guess because if you connect to that server with remote
desktop your remote session will live in just another window station.
http://bytes.com/topic/c-sharp/answers/543869-windows-service-process-start
http://support.microsoft.com/kb/115825