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
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Running an exe from Windows Services

Running an exe from Windows Services

Scheduled Pinned Locked Moved Managed C++/CLI
c++help
5 Posts 2 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.
  • N Offline
    N Offline
    nsurendran
    wrote on last edited by
    #1

    Hi All, I wrote a C++ program which will create a service in windows. By starting that service I want to run a particular .exe The issue here is that, after starting that service, that .exe is running in the task manager but the application window is not visible. I am giving the .exe path as a command line argument while executing the C++ exe. rgds., Surendran

    M 1 Reply Last reply
    0
    • N nsurendran

      Hi All, I wrote a C++ program which will create a service in windows. By starting that service I want to run a particular .exe The issue here is that, after starting that service, that .exe is running in the task manager but the application window is not visible. I am giving the .exe path as a command line argument while executing the C++ exe. rgds., Surendran

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

      If the service is running under a system account (SYSTEM, LocalService, etc.) then its child processes do too and they aren't visible by default on the interactive desktop. I believe the recommended way to run an app interactive is CreateProcessAsUser(). You shouldn't run the EXE as interactive and running in the service's account because that a) won't work in Vista and b) opens you up to elevation of priv attacks in pre-Vista.

      --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

      N 1 Reply Last reply
      0
      • M Michael Dunn

        If the service is running under a system account (SYSTEM, LocalService, etc.) then its child processes do too and they aren't visible by default on the interactive desktop. I believe the recommended way to run an app interactive is CreateProcessAsUser(). You shouldn't run the EXE as interactive and running in the service's account because that a) won't work in Vista and b) opens you up to elevation of priv attacks in pre-Vista.

        --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

        N Offline
        N Offline
        nsurendran
        wrote on last edited by
        #3

        Mike, Thanks for the info. In the CreateProcessAsUser( hToken, NULL, "cmd.exe" or cmdline args, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi ) This I got from one site, I want to know, apart from calling this function, anyotherfunction needs to be called?And for the "htoken" parameter any objects or assignments needs to be done? and FYI is now I am using CreateProcess method in the program Thanks N.Surendran

        M 1 Reply Last reply
        0
        • N nsurendran

          Mike, Thanks for the info. In the CreateProcessAsUser( hToken, NULL, "cmd.exe" or cmdline args, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi ) This I got from one site, I want to know, apart from calling this function, anyotherfunction needs to be called?And for the "htoken" parameter any objects or assignments needs to be done? and FYI is now I am using CreateProcess method in the program Thanks N.Surendran

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

          I ran across this blog post[^] yesterday, which has some info about using CreateProcessAsUser()

          --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

          N 1 Reply Last reply
          0
          • M Michael Dunn

            I ran across this blog post[^] yesterday, which has some info about using CreateProcessAsUser()

            --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

            N Offline
            N Offline
            nsurendran
            wrote on last edited by
            #5

            Hi , Thanks for the info. I wrote the code like below. In that ArgPBU is command line args (exe name to run) cwd is current working directory path BOOL b; HANDLE hToken; HANDLE hNewToken; b = OpenProcessToken(GetCurrentProcess(), TOKEN_ASSIGN_PRIMARY|TOKEN_DUPLICATE, &hToken); b = DuplicateTokenEx(hToken, TOKEN_ASSIGN_PRIMARY|TOKEN_ALL_ACCESS, NULL, SecurityImpersonation, TokenPrimary, &hNewToken); b = CreateProcessAsUser(hNewToken, NULL,ArgPBU,NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE, NULL, Cwd, &si, &m_piPBU); CloseHandle(hNewToken); ------------- After executing this I am getting same result. Can you help me in this regards? Surendran N

            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