Page 1 of 1

windows service & interact with desktop?

Posted: Tue Jan 18, 2011 6:04 pm
by jassing
I have a service that needs to appear in the system tray when someone logs in. Anyone know of a trick other than having a 2nd exe run at login?

Re: windows service & interact with desktop?

Posted: Wed Jan 19, 2011 4:26 pm
by IdeasVacuum
Not the answer to your question, but related: http://www.purebasic.fr/english/viewtop ... 12&t=45057

Re: windows service & interact with desktop?

Posted: Wed Jan 19, 2011 5:03 pm
by LuCiFeR[SD]
Personally, I would use the FindWindow API.

just get it to check every so often that the Shell_Traywnd is there... if it is, add the tray Icon. If not, check again in 30 seconds or something.

Re: windows service & interact with desktop?

Posted: Wed Jan 19, 2011 8:24 pm
by jassing
LuCiFeR[SD] wrote:Personally, I would use the FindWindow API.

just get it to check every so often that the Shell_Traywnd is there... if it is, add the tray Icon. If not, check again in 30 seconds or something.
Ah.. So if the service is running under a system account, if administrator logs in, it will be able to interact with that users desktop?

Interesting idea worth check into..

Re: windows service & interact with desktop?

Posted: Wed Jan 19, 2011 8:59 pm
by LuCiFeR[SD]
as the administrator, you are in charge of what users get access to whatever program. nothing to stop you checking what level of access a logged in user has and acting accordingly :) It won't do it by magic thats for sure hehe

Re: windows service & interact with desktop?

Posted: Wed Jan 19, 2011 9:59 pm
by LuCiFeR[SD]
Actually, let me expand upon this a little... :) This is just to give you a rough idea of what I mean...

Code: Select all

Procedure.i FindTaskBar()
  If FindWindow_("Shell_TrayWnd",0)
    
    If OpenLibrary(0,"shell32.dll")      
      *MAlloc = GetFunction(0, "IsUserAnAdmin")
      
      If CallCFunctionFast(*MAlloc) = 1      
        Debug "Current user is Administrator"
        ;- Add code to add tray etc here
        
      Else    
        
        Debug "Current user is not an Administrator"
        ;- Decide what to do here if the user is not an administrator
      EndIf 
      
      CloseLibrary(0)
    EndIf 
    
  EndIf

EndProcedure