deepak_garg deepak_garg - 1 month ago 8x
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.


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= ""