Running a windows service in any other account other than 'SYSTEM'
-
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
-
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
-
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
and programmatically???
-
and programmatically???
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
-
and programmatically???
You can specify a valid user name and password in the
lpServiceStartName
andlpPassword
parameters of the CreateService[^] API.«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) -
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
Thanks for the help :)
-
You can specify a valid user name and password in the
lpServiceStartName
andlpPassword
parameters of the CreateService[^] API.«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++)Thanks for help :)