次の方法で共有


Script to Change Service Account

Sometime back I was asked by one of my customer who wanted to change the startup account for SQLServer Service and SQLBrowser Service without manually going to SQL Server Configuration Manager and changing password there.

By the way, did you know...

  1. You should NOT change the password from Services.msc for SQL Server. Only supported way to change it is from Enterprise Manager (in SQL 2000) and Configuration Manager (in SQL 2005 onwards)
  2. If only service account password is changed using configuration manager, it does not need a restart of SQL Server Service.

Below is the script which could be used. Save the below script to .vbs file and make changes to reflect your instance name/Service name and account.

set sqlsvr = GetObject("WINMGMTS:\\.\root\Microsoft\SqlServer\ComputerManagement:SqlService.ServiceName='MSSQLSERVER',SQLServiceType=1")sqlsvr.SetServiceAccount "LocalSystem"

set browsersvr = GetObject("WINMGMTS:\\.\root\Microsoft\SqlServer\ComputerManagement:SqlService.ServiceName='SQLBrowser',SQLServiceType=1")

browsersvr.SetServiceAccount "NetworkService"

You can make changes to modify SQL Agent account as well. Hope this helps.

Comments

  • Anonymous
    March 23, 2010
    For #1 about Not changing the password from Services.msc is true for a cluster, but it that also true for stand-alone instances. I've heard that for clustered instances and understand why, but the reasons why would not apply to stand-alone instances.Can you clafiry, please? Why would that be unsupported for a stand-alone instance?

  • Anonymous
    March 23, 2010
    Hey Steve, Good Question. Changing service account would change permission of folders, registry etc. In SQL 2000, we change the permission for registry and files.In SQL 2005 we give just remove the account from the group and add back new account. Service.msc is not aware of SQL Server specific registry keys and folders which need to be change. Password change is OK. More details here... How to change the SQL Server or SQL Server Agent service account without using SQL Enterprise Manager in SQL Server 2000 or SQL Server Configuration Manager in SQL Server 2005 http://support.microsoft.com/kb/283811 Hope this helps. Balmukund

  • Anonymous
    January 01, 2011
    Thank you Balmukand,But is there a way to remotely find  what domain account my SQL server and agent is using.Patilhyd@gmail.com