470,581 Members | 2,433 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,581 developers. It's quick & easy.

Change Windows service to run under LocalSystem account from a user account (API)

Good day.

I would like to know if there is an API i can use to change windows service to run under LocalSystem account from a user account. Currently I am using the API below to change the service from using a LocalSystem account to a user account.

public static int ChangeService(string Name, string Password, string serviceName)
{
ManagementBaseObject inParams = null;

ManagementObject srvc = new ManagementObject("Win32_Service.Name='" + serviceName + "'");

inParams = srvc.GetMethodParameters("Change");

inParams["StartName"] = Name; //account name .\\localaccount;

// 'domain\\domainaccount' (or account@somedomain on XP and up)
inParams["StartPassword"] = Password; // password

ManagementBaseObject outParams = srvc.InvokeMethod("Change", inParams, null);

return System.Convert.ToInt32(outParams.Properties["ReturnValue"].Value);
}

But the problem now is that i cant change the service back to LocalSystem.

Many thanks in advance.
Nov 14 '06 #1
0 3416

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Glenn Venzke | last post: by
2 posts views Thread by JP | last post: by
9 posts views Thread by Hardy Wang | last post: by
3 posts views Thread by Bonj | last post: by
13 posts views Thread by J | last post: by
27 posts views Thread by pisquem | last post: by
1 post views Thread by livre | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.