<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Michiel Wories' WebLog : WMI Samples</title><link>http://blogs.msdn.com/mwories/archive/tags/WMI+Samples/default.aspx</link><description>Tags: WMI Samples</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>How to change the SQL Server password programmatically</title><link>http://blogs.msdn.com/mwories/archive/2006/11/03/wmi_5F00_change_5F00_password.aspx</link><pubDate>Sat, 04 Nov 2006 02:32:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:948273</guid><dc:creator>mwories</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/mwories/comments/948273.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mwories/commentrss.aspx?PostID=948273</wfw:commentRss><description>&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;Every now and the question comes up how to programmatically modify the service account or password of SQL Server. There basically two ways to accomplish this, using SMO, or WMI. This article shows you how to use WMI and VBScript to accomplish this task.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;There are a couple of things you need to know.&lt;/FONT&gt;&lt;/P&gt;
&lt;UL style="MARGIN-TOP: 0in" type=disc&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;&lt;FONT face="Times New Roman" size=3&gt;SQL Server &lt;U&gt;does not need a reboot&lt;/U&gt; when the password is modified. We (SQL Server Team) spent quite a bit of time ensuring you do not suffer any unnecessary downtime when performing an operation that has to happen regularly, when password are expiring. Everyone likes a ‘no reboot’ clause, right?&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;&lt;FONT face="Times New Roman" size=3&gt;When changing the account and password, the service does need a reboot, but the WMI Provider does this for you. In fact, if the service is not started it will be brought up for a short moment. If it already running it will be restarted. The reasons are as follows:&lt;/FONT&gt;&lt;/LI&gt;
&lt;UL style="MARGIN-TOP: 0in" type=circle&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level2 lfo1; tab-stops: list 1.0in"&gt;&lt;FONT face="Times New Roman" size=3&gt;The service master key needs to be re-encrypted&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level2 lfo1; tab-stops: list 1.0in"&gt;&lt;FONT face="Times New Roman" size=3&gt;Various other security settings are done&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;&lt;FONT face="Times New Roman" size=3&gt;Because the WMI Provider performs various operations besides changing the service account, other account change methods like ‘sc’ or the standard service control panel are not supported. You may see that the service will not start in some cases.&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;&lt;FONT face="Times New Roman" size=3&gt;Changing the password only tells the service that the password has changed. If you want to change the account’s password, use a command like NET USER. You need to run that first.&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;The following scripts allow you to change the service account + password, or only the password:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;setaccount.vbs:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt"&gt;‘ Set the account and password&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt"&gt;set svr = GetObject("WINMGMTS:\\.\root\Microsoft\SqlServer\ComputerManagement:SqlService.ServiceName='MSSQL$&lt;?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /&gt;&lt;st1:State w:st="on"&gt;&lt;st1:place w:st="on"&gt;YUKON&lt;/st1:place&gt;&lt;/st1:State&gt;',SQLServiceType=1")&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt"&gt;svr.SetServiceAccount ".\TestUser", "NewPassword!!"&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;setpwd.vbs:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt"&gt;‘ Set the password&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt"&gt;set svr = GetObject("WINMGMTS:\\.\root\Microsoft\SqlServer\ComputerManagement:SqlService.ServiceName='MSSQL$&lt;st1:place w:st="on"&gt;&lt;st1:State w:st="on"&gt;YUKON&lt;/st1:State&gt;&lt;/st1:place&gt;',SQLServiceType=1")&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt"&gt;svr.SetServiceAccountPassword "", "NewPassword2!!"&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;You need to change 'MSSQL$&lt;st1:State w:st="on"&gt;YUKON&lt;/st1:State&gt;' to match your instance name (replace ‘&lt;st1:State w:st="on"&gt;&lt;st1:place w:st="on"&gt;YUKON&lt;/st1:place&gt;&lt;/st1:State&gt;’ with the instance name, or the entire string with MSSQLSERVER for the default instance). Of course the account and password need to be changed as well.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;Try this on a test server first before running this on a production server.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;I hope this is helpful,&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;Michiel&lt;/FONT&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=948273" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mwories/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://blogs.msdn.com/mwories/archive/tags/WMI+Samples/default.aspx">WMI Samples</category></item><item><title>Starting with SQL Server 2005 WMI with help of Scriptomatic</title><link>http://blogs.msdn.com/mwories/archive/2005/04/27/sql-wmi-scriptomatic.aspx</link><pubDate>Thu, 28 Apr 2005 05:40:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:412801</guid><dc:creator>mwories</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/mwories/comments/412801.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mwories/commentrss.aspx?PostID=412801</wfw:commentRss><description>&lt;P&gt;SQL Server 2005 introduces a new WMI Provider that allows configuration of Services, Client Network Protocols, and Server Protocols. This is a great improvement for DBA that are managing many SQL Servers, as WMI allows you to query and modify SQL Server configuration settings remotely.&lt;/P&gt;
&lt;P&gt;Now, everyone who has&amp;nbsp;worked with WMI knows it's not easy to write a WMI program. You need to know the namespace, class names, etc. Everything that helps developers so well in VS (IntelliSense, object browsers) is not available to the scripters that are working on a bare system. I typically have a couple of WMI templates on my pen drive and start from there.&lt;/P&gt;
&lt;P&gt;I recently ran into &lt;STRONG&gt;&lt;FONT color=#006400&gt;Scriptomatic&lt;/FONT&gt;&lt;/STRONG&gt;. It's a great tool to give you good starting points for creating WMI scripts. It&amp;nbsp;provides you with a dropdown of namespaces available on the system, and classes within the selected namespace. It even allows creation of Perl&amp;nbsp;scripts...!&lt;/P&gt;
&lt;P&gt;Download it &lt;A href="http://www.microsoft.com/technet/scriptcenter/tools/scripto2.mspx"&gt;here&lt;/A&gt;&amp;nbsp;and then select the &lt;STRONG&gt;&lt;FONT color=#006400&gt;root\Microsoft\SqlServer\ComputerManagement&lt;/FONT&gt;&lt;/STRONG&gt; namespace; select the &lt;STRONG&gt;&lt;FONT color=#006400&gt;SqlService class&lt;/FONT&gt; &lt;/STRONG&gt;and voila, a ready to run script is displayed in the window. Quite nice! Here is an VbScript example:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color=#008000 size=1&gt;On Error Resume Next&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color=#008000 size=1&gt;Const wbemFlagReturnImmediately = &amp;amp;h10&lt;BR&gt;Const wbemFlagForwardOnly = &amp;amp;h20&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color=#008000 size=1&gt;arrComputers = Array("C3PO")&lt;BR&gt;For Each strComputer In arrComputers&lt;BR&gt;&amp;nbsp;&amp;nbsp; WScript.Echo&lt;BR&gt;&amp;nbsp;&amp;nbsp; WScript.Echo "=========================================="&lt;BR&gt;&amp;nbsp;&amp;nbsp; WScript.Echo "Computer: " &amp;amp; strComputer&lt;BR&gt;&amp;nbsp;&amp;nbsp; WScript.Echo "=========================================="&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color=#008000 size=1&gt;&amp;nbsp;&amp;nbsp; Set objWMIService = GetObject("winmgmts:\\" &amp;amp; strComputer &amp;amp; "\root\Microsoft\SqlServer\ComputerManagement")&lt;BR&gt;&amp;nbsp;&amp;nbsp; Set colItems = objWMIService.ExecQuery("SELECT * FROM SqlService", "WQL", _&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; wbemFlagReturnImmediately + wbemFlagForwardOnly)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color=#008000 size=1&gt;&amp;nbsp;&amp;nbsp; For Each objItem In colItems&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WScript.Echo "AcceptPause: " &amp;amp; objItem.AcceptPause&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WScript.Echo "AcceptStop: " &amp;amp; objItem.AcceptStop&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; strAdvancedProperties = Join(objItem.AdvancedProperties, ",")&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WScript.Echo "AdvancedProperties: " &amp;amp; strAdvancedProperties&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WScript.Echo "BinaryPath: " &amp;amp; objItem.BinaryPath&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WScript.Echo "Clustered: " &amp;amp; objItem.Clustered&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; strDependencies = Join(objItem.Dependencies, ",")&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WScript.Echo "Dependencies: " &amp;amp; strDependencies&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WScript.Echo "Description: " &amp;amp; objItem.Description&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WScript.Echo "DisplayName: " &amp;amp; objItem.DisplayName&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WScript.Echo "ErrorControl: " &amp;amp; objItem.ErrorControl&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WScript.Echo "ExitCode: " &amp;amp; objItem.ExitCode&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WScript.Echo "HostName: " &amp;amp; objItem.HostName&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WScript.Echo "ProcessId: " &amp;amp; objItem.ProcessId&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WScript.Echo "ServiceName: " &amp;amp; objItem.ServiceName&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WScript.Echo "SQLServiceType: " &amp;amp; objItem.SQLServiceType&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WScript.Echo "StartMode: " &amp;amp; objItem.StartMode&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WScript.Echo "StartName: " &amp;amp; objItem.StartName&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WScript.Echo "State: " &amp;amp; objItem.State&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WScript.Echo&lt;BR&gt;&amp;nbsp;&amp;nbsp; Next&lt;BR&gt;Next&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=412801" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mwories/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://blogs.msdn.com/mwories/archive/tags/WMI+Samples/default.aspx">WMI Samples</category></item></channel></rss>