{"id":87,"date":"2006-03-29T08:16:00","date_gmt":"2006-03-29T15:16:00","guid":{"rendered":"http:\/\/www.jasemccarty.com\/blog\/2006\/03\/vbs-update-services-password-on-localremote-box.html"},"modified":"2006-03-29T08:16:00","modified_gmt":"2006-03-29T15:16:00","slug":"vbs-update-services-password-on-localremote-box","status":"publish","type":"post","link":"https:\/\/www.jasemccarty.com\/blog\/vbs-update-services-password-on-localremote-box\/","title":{"rendered":"VBS: Update Services Password on Local\/Remote Box"},"content":{"rendered":"<div><span class=\"010130715-29032006\"  style=\"font-size:100%;\"><span style=\";font-family:Arial;\" >This script, will  allow you to update passwords for services that &#8220;Log on As&#8221; set to use a domain  account.<\/span><\/span><\/div>\n<div><span class=\"010130715-29032006\"  style=\"font-size:100%;\"><span style=\";font-family:Arial;\" ><\/span><\/span> <\/div>\n<div><span class=\"010130715-29032006\"  style=\"font-size:100%;\"><span style=\";font-family:Arial;\" >You can download it  <strong><a href=\"\/scripts\/UPD8SVCS_vbs.txt\">here<\/a><\/strong>.<\/span><\/span><\/div>\n<div><span class=\"010130715-29032006\"><span style=\";font-family:Arial;font-size:85%;\"  ><\/span><\/span> <\/div>\n<div><span class=\"010130715-29032006\"><span style=\";font-family:Arial;font-size:85%;\"  >&#8216;***********************************************************<br \/>&#8216;Written  by Jase McCarty<br \/>&#8216;Date: 03\/29\/2006<br \/>&#8216;<br \/>&#8216;UPD8SVCS.vbs<br \/>&#8216;<br \/>&#8216;Description:  Change the password on a local<br \/>&#8216;or remote system for a Service that  has <br \/>&#8216;&#8221;Logon As&#8221; set for a Domain Account<br \/>&#8216;Useful for Servers  when a service account<br \/>&#8216;has a password  change<br \/>&#8216;***********************************************************<\/span><\/span><\/div>\n<div><span style=\";font-family:Arial;font-size:85%;\"  ><\/span> <\/div>\n<div><span class=\"010130715-29032006\"><span style=\";font-family:Arial;font-size:85%;\"  >Option  Explicit<\/span><\/span><\/div>\n<div><span style=\";font-family:Arial;font-size:85%;\"  ><\/span> <\/div>\n<div><span class=\"010130715-29032006\"><span style=\";font-family:Arial;font-size:85%;\"  > Dim  shellobj,env<br \/>Dim  strUserDomain,strUserName,strPassword,strComputer<br \/>Dim  CSComputerName,CSAccount,CSPassword,objWMIService<br \/>Dim  objService<\/span><\/span><\/div>\n<div><span style=\";font-family:Arial;font-size:85%;\"  ><\/span> <\/div>\n<div><span class=\"010130715-29032006\"><span style=\";font-family:Arial;font-size:85%;\"  > &#8216;Check to make  sure that we receive enough arguements (2 or more)<br \/> If  Wscript.Arguments.Count &lt; 2 Then<\/p>\n<p>   Wscript.Echo &#8220;Usage: UPD8SVCS.vbs USERNAME PASSWORD  COMPUTERNAME&#8221;<br \/>  Wscript.Quit<\/p>\n<p>  Else<\/p>\n<p>  &#8216;Create a Shell Object &#038; be able to  get environment variables<br \/>  Set shellobj =  CreateObject(&#8220;Wscript.Shell&#8221;)<br \/>  Set env =  shellobj.Environment(&#8220;process&#8221;) <\/span><\/span><\/div>\n<div><span style=\";font-family:Arial;font-size:85%;\"  ><\/span> <\/div>\n<div><span class=\"010130715-29032006\"><span style=\";font-family:Arial;font-size:85%;\"  >  &#8216;Setup  default domain for credentials<br \/> &#8216;(could be modified to be an  attribute) <br \/>  strUserDomain =  env(&#8220;USERDOMAIN&#8221;)<br \/> strUserName =  Wscript.Arguments(0)<br \/> strPassword =  Wscript.Arguments(1)<\/p>\n<p> &#8216;Check to make sure we have  enough arguements (2 or more)<br \/> If Wscript.Arguments.Count &gt; 2  Then<br \/>  &#8216;If we 3, then the Computername will be the 3rd  arguement<br \/>  strComputer =  Wscript.Arguments(2)<br \/> Else<br \/>  &#8216;If we only  receive the first 2, then the Computername<br \/>  &#8216;will be the  local computer<br \/>  strcomputer =  env(&#8220;COMPUTERNAME&#8221;)<br \/> End If<\/p>\n<p> &#8216;Call  the ChangeServices subroutine<br \/> Call  ChangeServices(strComputer,strUserDomain &#038; &#8220;&#8221; &amp;  strUserName,strPassword)<\/p>\n<p>   WScript.Quit<\/p>\n<p>End  If<\/p>\n<p>&#8216;The ChangeServices SubRoutine<br \/>&#8216;This  requires a computername, account,and password to be passed to  it   <br \/>Sub  ChangeServices(CSComputerName,CSAccount,CSPassword)<\/span><\/span><\/div>\n<div><span style=\";font-family:Arial;font-size:85%;\"  ><\/span> <\/div>\n<div><span class=\"010130715-29032006\"><span style=\";font-family:Arial;font-size:85%;\"  >   &#8216;Setup a WMIService object, and setup a query to put  all services in an array<br \/>  Set objWMIService =  GetObject(&#8220;winmgmts:\\&#8221; &#038; CSComputerName &amp;  &#8220;rootcimv2&#8221;)<br \/>  Set colItems =  objWMIService.ExecQuery(&#8220;Select * from  Win32_Service&#8221;,,48)<\/p>\n<p>  &#8216;Loop through the  array<br \/>  For Each objService in  colItems        <\/span><\/span><\/div>\n<div><span style=\";font-family:Arial;font-size:85%;\"  ><\/span> <\/div>\n<div><span class=\"010130715-29032006\"><span style=\";font-family:Arial;font-size:85%;\"  >    &#8216;If the &#8220;Logon As&#8221; of the current service matches  the user specified,<br \/>   &#8216;change the password to the one  specified<br \/>   If Lcase(objService.StartName) =  LCase(CSAccount) Then<br \/>    &#8216;Make the credentials  change<br \/>    errReturn =  objService.Change(,,,,,,CSAccount,CSPassword)<\/p>\n<p>    &#8216;Write  to the screen and the computer&#8217;s event log, the success or failure<br \/>    If err.number &lt;&gt; 0  then<br \/>      shellobj.LogEvent 1,&#8221;Failure  Changing Username and Password for &#8221; _<br \/>           &#038; objService.DisplayName &amp; &#8221; run by user &#8221;  &#038; CSAccount &amp; &#8220;.&#8221;<br \/>      Wscript.Echo  &#8220;Failure Changing Username and Password for &#8221;  _<br \/>          &#038;  objService.DisplayName &amp; &#8221; run by user &#8221; &#038; CSAccount &amp;  &#8220;.&#8221;<br \/>    Else<br \/>       shellobj.LogEvent 0,&#8221;Successfully Changed Username and Password for  &#8221; _<br \/>          &#038;  objService.DisplayName &amp; &#8221; run by user &#8221; &#038; CSAccount &amp;  &#8220;.&#8221;<br \/>      Wscript.Echo &#8220;Successfully Changed  Username and Password for &#8221; _<br \/>           &#038; objService.DisplayName &amp; &#8221; run by  user &#8221; &#038; CSAccount &amp; &#8220;.&#8221;<br \/>    End  If<\/p>\n<p>   End  If<\/p>\n<p>  Next          <\/span><\/span><\/div>\n<div><span class=\"010130715-29032006\"><span style=\";font-family:Arial;font-size:85%;\"  > <br \/>End Sub<\/span><\/span><\/div>\n<div><span style=\";font-family:Arial;font-size:85%;\"  ><\/span> <\/div>\n<div><span class=\"010130715-29032006\"><span style=\";font-family:Arial;font-size:85%;\"  ><\/span><\/span> <\/div>\n","protected":false},"excerpt":{"rendered":"<p>This script, will allow you to update passwords for services that &#8220;Log on As&#8221; set to use a domain account. You can download it here. &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-87","post","type-post","status-publish","format-standard","hentry","category-vbs"],"_links":{"self":[{"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/posts\/87","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/comments?post=87"}],"version-history":[{"count":0,"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/posts\/87\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/media?parent=87"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/categories?post=87"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/tags?post=87"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}