How to make a service start after logon ?

I have created a service in delphi which runs another application. The reason for this is because the application it runs needs to run as a more privileged user. The problem I am having is that the service runs and executes the application before the logon.

The question is; how can I make the service wait until a user has logged on ?
marhk51Asked:
Who is Participating?
 
developmentguruConnect With a Mentor PresidentCommented:
 I would start by trying to respond to the message WM_WTS_SESSION change.  I believe the value you would be waiting to see is WTS_CONSOLE_CONNECT.  Then fire up your application.  There are many places to find info on how to add a message method to your objects so I will not clutter this post with it.  Here is a link to the msdn info.
http://msdn2.microsoft.com/en-us/library/Aa383828.aspx

You must register to get these notification messages:
http://msdn2.microsoft.com/en-us/library/aa383841.aspx

Here is some more reading:
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_20525770.html
http://www.delphiresources.com/documentations/tips-tricks/system/how-can-i-receive-session-switch-notifications-xp/viewlink.html

Let me know if you need more info
0
 
ziolkoCommented:
you can't user may never logon but all services with automatic startup must be started thats why user logon is independent from service startup.

i've seen somwhere in MSDN methods for signup for login/logoff notifications

ziolko.
0
 
marhk51Author Commented:
so is there a way I can check if there is a user logged on from within the service before launching the app ?
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
ziolkoCommented:
about notifications see here:
http://msdn2.microsoft.com/en-us/library/aa380543.aspx
but it aint easy task.

you can make your service to go in loop until someone will logon.

ziolko.
0
 
marhk51Author Commented:
yes, where can I download these notification dlls and supporting documentation ?
0
 
ziolkoCommented:
if you know name and pass of user you want to be owner of process you might try createprocessasuser or createprocesswithlogon

ziolko
0
 
developmentguruPresidentCommented:
(Your service will start like it always has, but you can wait to start the applicatioon until a user is logged in - or delay another 30 seconds... whatever you need)
0
 
marhk51Author Commented:
Thanks to everyone who responded.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.