deepak_garg deepak_garg - 1 year ago 184
C# Question

Log on of sql service as LocalSystem

I am struggling in a issue related to windows services.

In my project , I want to change the sql service 'LOG ON AS' Local System using c# code.

Answer Source

You can do it in C# this way:

var process = new System.Diagnostics.Process();
process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments= "/c sc.exe config \"mssql$sqlexpress\" obj= \"localsystem\" password= \"\"";


  • Pay attention to space after obj= and password=
  • isntead of mssql$sqlexpress, use your service name.
  • you may need run as administrator.
  • If you open the command prompt and run this command, your service account will change to local system account:sc.exe config "mssql$sqlexpress" obj= "localsystem" password= ""
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download