Tricky NT Service Question
-
G'Day All I am writing an NT service that uses some MAPI stuff. According to MSDN (and experimentation) it seems that must run without a desktop. Which is fine and indeed I have that part working. However I would like to add some functionality to this service such that it needs to interact with the desktop - specifically I would like it to manipulate the system tray. Now I believe that system tray manipulation needs a handle to a window but my problem is because the MAPI stuff requires no desktop I don't know how I can grab one. I had tried to enumerate child windows until I found the one I wanted but of course because there is no desktop that call returns no windows. So I was wondering whether anyone had a good idea as to how best to get around this? Is it possible to have the service start another exe/process/thread to do the manipulation which would have access to the desktop but not place a button on the task bar.... Much thanks for your thoughts, Richard Ellis.
-
G'Day All I am writing an NT service that uses some MAPI stuff. According to MSDN (and experimentation) it seems that must run without a desktop. Which is fine and indeed I have that part working. However I would like to add some functionality to this service such that it needs to interact with the desktop - specifically I would like it to manipulate the system tray. Now I believe that system tray manipulation needs a handle to a window but my problem is because the MAPI stuff requires no desktop I don't know how I can grab one. I had tried to enumerate child windows until I found the one I wanted but of course because there is no desktop that call returns no windows. So I was wondering whether anyone had a good idea as to how best to get around this? Is it possible to have the service start another exe/process/thread to do the manipulation which would have access to the desktop but not place a button on the task bar.... Much thanks for your thoughts, Richard Ellis.
Use GetDesktopWindow(). If it returns NULL, it means the desktop is not up yet. Once you have the desktop up, you can do all the tray adding stuff. Nish Sonork ID 100.9786 voidmain www.busterboy.org If you don't find me on CP, I'll be at Bob's HungOut
-
G'Day All I am writing an NT service that uses some MAPI stuff. According to MSDN (and experimentation) it seems that must run without a desktop. Which is fine and indeed I have that part working. However I would like to add some functionality to this service such that it needs to interact with the desktop - specifically I would like it to manipulate the system tray. Now I believe that system tray manipulation needs a handle to a window but my problem is because the MAPI stuff requires no desktop I don't know how I can grab one. I had tried to enumerate child windows until I found the one I wanted but of course because there is no desktop that call returns no windows. So I was wondering whether anyone had a good idea as to how best to get around this? Is it possible to have the service start another exe/process/thread to do the manipulation which would have access to the desktop but not place a button on the task bar.... Much thanks for your thoughts, Richard Ellis.
Call
RegisterWindowMessage(_T("TaskbarCreated"))
. That message is broadcast by the shell when the taskbard is created. Use that to tell when you can add your tray icon. (Requires shell 4.71+, however) --Mike-- "Everyone has figured out what 'service pack' really means, so they had to go and change the language. Perhaps this is what Bill was talking about in the 'security is top priority' letter." -- Daniel Ferguson, 1/31/2002 My really out-of-date homepage Sonork - 100.10414 AcidHelm Big fan of Alyson Hannigan. -
G'Day All I am writing an NT service that uses some MAPI stuff. According to MSDN (and experimentation) it seems that must run without a desktop. Which is fine and indeed I have that part working. However I would like to add some functionality to this service such that it needs to interact with the desktop - specifically I would like it to manipulate the system tray. Now I believe that system tray manipulation needs a handle to a window but my problem is because the MAPI stuff requires no desktop I don't know how I can grab one. I had tried to enumerate child windows until I found the one I wanted but of course because there is no desktop that call returns no windows. So I was wondering whether anyone had a good idea as to how best to get around this? Is it possible to have the service start another exe/process/thread to do the manipulation which would have access to the desktop but not place a button on the task bar.... Much thanks for your thoughts, Richard Ellis.
Richard Ellis wrote: So I was wondering whether anyone had a good idea as to how best to get around this? Is it possible to have the service start another exe/process/thread to do the manipulation which would have access to the desktop but not place a button on the task bar.... Usually when there is need for GUI presence in any non-gui service/driver, the safest solution is just another service which starts after the non-gui one (set dependency in the registry) and use IPC (LPC, pipes, etc.) cheers Andreas
-
Richard Ellis wrote: So I was wondering whether anyone had a good idea as to how best to get around this? Is it possible to have the service start another exe/process/thread to do the manipulation which would have access to the desktop but not place a button on the task bar.... Usually when there is need for GUI presence in any non-gui service/driver, the safest solution is just another service which starts after the non-gui one (set dependency in the registry) and use IPC (LPC, pipes, etc.) cheers Andreas
Thankyou very much Gentlemen for your replies. That was enough to get me searching for a few things I had not thought of. I ended up coming across an article in MSDN that showed me how to create a process from with a NT Service. It seems to work well. FYI my code is below STARTUPINFO si; PROCESS_INFORMATION ProcessInformation; si.cb = sizeof(STARTUPINFO); si.lpReserved = NULL; si.lpTitle = NULL; si.lpDesktop = "WinSta0\\Default"; si.dwX = si.dwY = si.dwXSize = si.dwYSize = 0L; si.dwFlags = STARTF_USESHOWWINDOW; si.wShowWindow = SW_HIDE; si.lpReserved2 = NULL; si.cbReserved2 = 0; if (CreateProcess(NULL, "some exe name", NULL, NULL, FALSE, 0, NULL, NULL, &si, &ProcessInformation)) { LogText(" process created"); CloseHandle(ProcessInformation.hProcess); CloseHandle(ProcessInformation.hThread); } else { LogText("CreateProcess failed. Error %d\n", GetLastError()); } Richard Ellis.