I want to change the logon properties of a sql server 2008 r2 instance by using code. Manually i can do it in SQL server configuration manager by right clicking on instance name->Log On. Under Built-in account change Network service to Local service. Then click on apply. SQL instance will be restarted to effect the changes.
Now hoe can i do the same(Network service to Local service) using code .I think it can be done using WMI. So please help me on this.
Changing logon properties from Network service to localSystem can be done by using WMI.
Use Change method of the Win32_Service class
In change method specify first 6 parameters blank and then specify StartName as LocalSystem(You can also specify other parameters such as login names if required) and StartPassword as a blank password(Blank password in case of localsystem).
Below is a vbscript to do it.
strComputer = "."
Set objWMIService = GetObject _
("winmgmts:\\" & strComputer & "\root\cimv2")
Set colServices = objWMIService.ExecQuery _
("Select * From Win32_Service where Name = 'MSSQL$Instancename'")
For Each objService in colServices
errReturn = objService.Change( , , , , , , "LocalSystem","")
Next
Also see this link for more information