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. C / C++ / MFC
  4. start an .exe from windows service

start an .exe from windows service

Scheduled Pinned Locked Moved C / C++ / MFC
help
5 Posts 3 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, I want to run an exe(say for eg: Calculator) from the windows service when it started. In the OnInit() I have used CreateProcess function, toget the exe path from the command line argument. My problem here is that, Exe and service is running in task manafer after I started the service, But I couldnt see the application window(Calculator) visible to user. After getting some valuable suggestion from this site, I replaced CreateProcess function with CreateProcessAsUser() function to get the window. But Still the same problem exists. Here is the code I place in the Init menthod 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); ----------------------- Thanks in advance. Rgds., Surendran N

    K 1 Reply Last reply
    0
    • N nsurendran

      Hi, I want to run an exe(say for eg: Calculator) from the windows service when it started. In the OnInit() I have used CreateProcess function, toget the exe path from the command line argument. My problem here is that, Exe and service is running in task manafer after I started the service, But I couldnt see the application window(Calculator) visible to user. After getting some valuable suggestion from this site, I replaced CreateProcess function with CreateProcessAsUser() function to get the window. But Still the same problem exists. Here is the code I place in the Init menthod 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); ----------------------- Thanks in advance. Rgds., Surendran N

      K Offline
      K Offline
      kakan
      wrote on last edited by
      #2

      I have been working with this problem recently, in Windows Server 2003. I started a GUI app as a service (with XYNTService), but I couldn't see the app window either. I found out that the only account that could interact with the desktop is (at least in 2003) is services running under Local Account. I tried it, but as expeced, the Local Account cannot access the network. I ended up with doing an autologin to the preferred user account, then autostart the GUI app. The biggest drawback is that if a user performs a logoff, the app is closed, so I had to make a Windows wallpaper saying: "Don't logoff, just do a "lock computer". I'm really interested in a better solution, I really hope you will get a better answer than this one.

      Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson

      B 1 Reply Last reply
      0
      • K kakan

        I have been working with this problem recently, in Windows Server 2003. I started a GUI app as a service (with XYNTService), but I couldn't see the app window either. I found out that the only account that could interact with the desktop is (at least in 2003) is services running under Local Account. I tried it, but as expeced, the Local Account cannot access the network. I ended up with doing an autologin to the preferred user account, then autostart the GUI app. The biggest drawback is that if a user performs a logoff, the app is closed, so I had to make a Windows wallpaper saying: "Don't logoff, just do a "lock computer". I'm really interested in a better solution, I really hope you will get a better answer than this one.

        Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson

        B Offline
        B Offline
        bolivar123
        wrote on last edited by
        #3

        When you create your service via call to CreateService, be sure to include the SERVICE_INTERACTIVE_PROCESS. This will allow your service to interact with the desktop. ::CreateService( hSCM, m_szServiceName, m_szServiceName, SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, szFilePath, NULL, NULL, _T("RPCSS\0"), NULL, NULL);

        K N 2 Replies Last reply
        0
        • B bolivar123

          When you create your service via call to CreateService, be sure to include the SERVICE_INTERACTIVE_PROCESS. This will allow your service to interact with the desktop. ::CreateService( hSCM, m_szServiceName, m_szServiceName, SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, szFilePath, NULL, NULL, _T("RPCSS\0"), NULL, NULL);

          K Offline
          K Offline
          kakan
          wrote on last edited by
          #4

          Thanks. I will check out if XYNTService does this as it is. But i think it does, since it has been working (with GUI apps) in other Windows versions. In the properties dialog in Windows 2003 Server, the "Interact with desktop" checkbox, is disabled unless "Local Account" is selected (for a service).

          Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson

          1 Reply Last reply
          0
          • B bolivar123

            When you create your service via call to CreateService, be sure to include the SERVICE_INTERACTIVE_PROCESS. This will allow your service to interact with the desktop. ::CreateService( hSCM, m_szServiceName, m_szServiceName, SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, szFilePath, NULL, NULL, _T("RPCSS\0"), NULL, NULL);

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

            Yes in my program CreateService is mentioned like this only. One thing I have to mention here is that, I found that the application GUI is launching when the service starts from the local machine, if the same machine is accessed from remote as Remotedesktop connection to start the service, the GUI is running only in the background. GUI is not visible. Rgds., Surendran

            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