Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Tricky NT Service Question

Tricky NT Service Question

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelpdiscussionlearning
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Richard Ellis
    wrote on last edited by
    #1

    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.

    N M A 3 Replies Last reply
    0
    • R 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.

      N Offline
      N Offline
      Nish Nishant
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • R 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.

        M Offline
        M Offline
        Michael Dunn
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • R 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.

          A Offline
          A Offline
          Andreas Saurwein
          wrote on last edited by
          #4

          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

          R 1 Reply Last reply
          0
          • A Andreas Saurwein

            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

            R Offline
            R Offline
            Richard Ellis
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups