Page 1 of 1

How do I display a message to user from service Win 7?

Posted: Wed Nov 16, 2011 2:34 am
by em_uk
Hi,

I have previously posted in the coding questions but the subtopic is more relevant.

I need to display a message to the logged on from a service, Windows XP allows me to do this but in Vista upwards session 0 is segregated from a logged on user for security reasons and requires a different approach.

My service uses SERVICE_INTERACTIVE_PROCESS and my MessageBox has the MB_SERVICE_NOTIFICATION flag.

I have found some resources regarding allowing interaction : http://msdn.microsoft.com/en-us/library ... 85%29.aspx but they are way over my head and I am not sure what I may need to include

http://msdn.microsoft.com/en-us/library ... 85%29.aspx

Re: How do I display a message to user from service Win 7?

Posted: Wed Nov 16, 2011 5:01 am
by buddymatkona
Here is a suggested way (with source) to create an interactive service on Vista/7.
The MSI you provide installs with one UAC popup to run as Admin...followed by a Reboot. After that the service should work as in XP. Hope it helps.

http://www.codeproject.com/KB/vista-sec ... sg=3316993

Re: How do I display a message to user from service Win 7?

Posted: Wed Nov 16, 2011 2:26 pm
by em_uk
Thanks for the info, however I don't think PB has support for some of the API functions, like WTSGetActiveConsoleSessionId. Unless I am missing something....

Re: How do I display a message to user from service Win 7?

Posted: Wed Nov 16, 2011 8:47 pm
by buddymatkona
@ em_uk
The good news is standard PB tools are enough to do API calls yourself.
In the case of WTSGetActiveConsoleSessionId, do this:

Code: Select all

Prototype ProtoConsoleSessionId() ; Prototype.d was my first guess and wrong - when in doubt, let PB handle parameter types
If OpenLibrary(0, "Kernel32.DLL")
    SessionId.ProtoConsoleSessionId = GetFunction(0, "WTSGetActiveConsoleSessionId")
    Result = SessionId()
    Debug Result ; on Windows 7 (System SessionId = 0) with a single user owning the console,  you should get  Result = 1 
   CloseLibrary(0)
 EndIf
Good Luck :)

Re: How do I display a message to user from service Win 7?

Posted: Wed Nov 16, 2011 10:37 pm
by em_uk
Wow! That's a real help! Thanks man! Seriously...