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. Running a windows service in any other account other than 'SYSTEM'

Running a windows service in any other account other than 'SYSTEM'

Scheduled Pinned Locked Moved C / C++ / MFC
question
7 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.
  • K Offline
    K Offline
    Kushagra Tiwari
    wrote on last edited by
    #1

    I want to install a service in such a way that if started from service manager then It should start from a particular user account and not from System account. How can this be done ?? Kushagra

    C 1 Reply Last reply
    0
    • K Kushagra Tiwari

      I want to install a service in such a way that if started from service manager then It should start from a particular user account and not from System account. How can this be done ?? Kushagra

      C Offline
      C Offline
      Covean
      wrote on last edited by
      #2

      If you just wanna use a "static" user (not dynamic) then just use the possibility to assign a valid user account and set this user instead of local system (second tab on service-properties).

      Greetings Covean

      K 1 Reply Last reply
      0
      • C Covean

        If you just wanna use a "static" user (not dynamic) then just use the possibility to assign a valid user account and set this user instead of local system (second tab on service-properties).

        Greetings Covean

        K Offline
        K Offline
        Kushagra Tiwari
        wrote on last edited by
        #3

        and programmatically???

        C _ 2 Replies Last reply
        0
        • K Kushagra Tiwari

          and programmatically???

          C Offline
          C Offline
          Covean
          wrote on last edited by
          #4

          On install-time with service installer:

          [RunInstallerAttribute(true)]
          public class ControllerInstaller : Installer
          {

          public ControllerInstaller()
                {
                      processInstaller=new ServiceProcessInstaller();
                      serviceInstaller=new ServiceInstaller();
                      processInstaller.Account=ServiceAccount.LocalSystem; <----------- here
                      serviceInstaller.StartType=ServiceStartMode.Automatic;
                      serviceInstaller.DisplayName = "DisplayName";
                      serviceInstaller.ServiceName = "ServiceName";
                      Installers.Add(serviceInstaller);
                      Installers.Add(processInstaller);
                }

          private ServiceInstaller serviceInstaller;
                private ServiceProcessInstaller processInstaller;
          }

          ; or CreateService (Win-API). At least look at the functions ChangeServiceConfig/ChangeServiceConfig2 if you want to change it "live"/for the next start.

          Greetings Covean

          K 1 Reply Last reply
          0
          • K Kushagra Tiwari

            and programmatically???

            _ Offline
            _ Offline
            _Superman_
            wrote on last edited by
            #5

            You can specify a valid user name and password in the lpServiceStartName and lpPassword parameters of the CreateService[^] API.

            «_Superman_» I love work. It gives me something to do between weekends.
            Microsoft MVP (Visual C++)

            K 1 Reply Last reply
            0
            • C Covean

              On install-time with service installer:

              [RunInstallerAttribute(true)]
              public class ControllerInstaller : Installer
              {

              public ControllerInstaller()
                    {
                          processInstaller=new ServiceProcessInstaller();
                          serviceInstaller=new ServiceInstaller();
                          processInstaller.Account=ServiceAccount.LocalSystem; <----------- here
                          serviceInstaller.StartType=ServiceStartMode.Automatic;
                          serviceInstaller.DisplayName = "DisplayName";
                          serviceInstaller.ServiceName = "ServiceName";
                          Installers.Add(serviceInstaller);
                          Installers.Add(processInstaller);
                    }

              private ServiceInstaller serviceInstaller;
                    private ServiceProcessInstaller processInstaller;
              }

              ; or CreateService (Win-API). At least look at the functions ChangeServiceConfig/ChangeServiceConfig2 if you want to change it "live"/for the next start.

              Greetings Covean

              K Offline
              K Offline
              Kushagra Tiwari
              wrote on last edited by
              #6

              Thanks for the help :)

              1 Reply Last reply
              0
              • _ _Superman_

                You can specify a valid user name and password in the lpServiceStartName and lpPassword parameters of the CreateService[^] API.

                «_Superman_» I love work. It gives me something to do between weekends.
                Microsoft MVP (Visual C++)

                K Offline
                K Offline
                Kushagra Tiwari
                wrote on last edited by
                #7

                Thanks for help :)

                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