Microsoft KB Archive/936492

= How to use Windows Management Instrumentation in SQL Server 2005 to change the account of the SQL Server service or the password of the SQL Server service programmatically =

Article ID: 936492

Article Last Modified on 11/20/2007

-

APPLIES TO


 * Microsoft SQL Server 2005 Developer Edition
 * Microsoft SQL Server 2005 Enterprise Edition
 * Microsoft SQL Server 2005 Standard Edition
 * Microsoft SQL Server 2005 Standard X64 Edition
 * Microsoft SQL Server 2005 Standard Edition for Itanium-based Systems
 * Microsoft SQL Server 2005 Enterprise X64 Edition
 * Microsoft SQL Server 2005 Enterprise Edition for Itanium-based Systems
 * Microsoft SQL Server 2005 Workgroup Edition
 * Microsoft SQL Server 2005 Express Edition
 * Microsoft SQL Server 2005 Express Edition with Advanced Services

-



INTRODUCTION
This article describes how to use Microsoft Windows Management Instrumentation (WMI) in Microsoft SQL Server 2005 to change either of the following items:
 * The account of the SQL Server service
 * The password of the SQL Server service



MORE INFORMATION
To use SQL Server 2005 to change the account of the SQL Server service or the password of the SQL Server service programmatically, you can use either of the following methods:
 * Use SQL Server Management Objects (SMO).
 * Use Windows Management Instrumentation (WMI). This article describes how to use WMI to perform this task.

Before you use WMI to change the account or the password, consider the following information:  After you change only the password, you do not have to restart the SQL Server service. You can avoid any unnecessary downtime when you have to change the password regularly. When you change the account or when you change the account and the password, you must restart the SQL Server service. However, the WMI provider automatically restarts the SQL Server service. If the SQL Server service is not started, the WMI provider starts the service. If the SQL Server service is running, the WMI provider restarts the service. The SQL Server service must be restarted because the following conditions are true:  The service master key must be reencrypted. Some other security settings must be set.  Microsoft does not support using the following methods to change the account of the SQL Server service or the password of the SQL Server service:  The sc command</li> Using the Services Microsoft Management Console (MMC) snap-in</li></ul>

You cannot use these methods because the WMI provider also performs additional operations when it changes the service account. These operations are not performed if you use these unsupported methods.</li></ul>

To change the account of the SQL Server service or the password of the SQL Server service, use one of the following scripts.

Note Paste one of the Visual Basic scripts into a .vbs file. For example, you name the file SetAccountPassword.vbs. Then, run the .vbs file.   Use the following script to change the account and the password of the SQL Server service: 'Set the account and the password. set svr = GetObject(&quot;WINMGMTS:\\.\root\Microsoft\SqlServer\ComputerManagement:SqlService.ServiceName='<MSSQL$InstanceName>',SQLServiceType=1&quot;)

svr.SetServiceAccount &quot;<Account>&quot;, &quot;<Password>&quot; </li>  Use the following script to change only the password of the SQL Server service: 'Set the password. set svr = GetObject(&quot;WINMGMTS:\\.\root\Microsoft\SqlServer\ComputerManagement:SqlService.ServiceName='<MSSQL$InstanceName>',SQLServiceType=1&quot;) svr.SetServiceAccountPassword &quot;&quot;, &quot;<New_Password>&quot; </li></ul>

Note In these scripts, you must change  to a value that corresponds to your configuration. If you run a default instance of SQL Server 2005, change  to MSSQLSERVER. If you run a named instance of SQL Server 2005, change  to MSSQL$.

We recommend that you test the script on a test server before you run the script on a production server.

Keywords: kbhowto kbinfo kbexpertiseadvanced kbsql2005engine KB936492

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.