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

Windows specific forum
User avatar
em_uk
Enthusiast
Enthusiast
Posts: 366
Joined: Sun Aug 08, 2010 3:32 pm
Location: Manchester UK

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

Post 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
----

R Tape loading error, 0:1
buddymatkona
Enthusiast
Enthusiast
Posts: 252
Joined: Mon Aug 16, 2010 4:29 am

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

Post 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
User avatar
em_uk
Enthusiast
Enthusiast
Posts: 366
Joined: Sun Aug 08, 2010 3:32 pm
Location: Manchester UK

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

Post 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....
----

R Tape loading error, 0:1
buddymatkona
Enthusiast
Enthusiast
Posts: 252
Joined: Mon Aug 16, 2010 4:29 am

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

Post 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 :)
User avatar
em_uk
Enthusiast
Enthusiast
Posts: 366
Joined: Sun Aug 08, 2010 3:32 pm
Location: Manchester UK

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

Post by em_uk »

Wow! That's a real help! Thanks man! Seriously...
----

R Tape loading error, 0:1
Post Reply