Freigeben über


A simple VBScript for Syncing IUSR password from Metabase to SAM

I always wanted this handy script. Searched for it, couldn't find one. Yes, there is iissuba.dll to do this, but I don't want to use that. I wanted a .vbs file like synciwam.vbs to sync the IUSR password stored in the Metabase with the one in Security Account Manager.

To do this, first we need to know how to get the properties of the Metabase. We can get the AnonymousUserName by the following code:

set WebServiceObj = GetObject("IIS://LocalHost/w3svc")

AnonymousUserName = WebServiceObj.AnonymousUserName

AnonymousUserPass = WebServiceObj.AnonymousUserPass

This code will fetch the Metabase properties. And now, I wanted to get the System name. Check the following code snippet:

set objNet = CreateObject("WScript.NetWork")

ComputerName = objNet.ComputerName

 

And now, we want to set the password of the user in SAM.

Set objUser = GetObject("WinNT://" & objNet.ComputerName & "/" & AnonymousUserName)

objUser.SetPassword(AnonymousUserPass)

objUser.SetInfo

 

Here is the complete code which will read the AnonymousUserPass set in /W3SVC in Metabase and set that password in the SAM for IUSR account.

set objNet = CreateObject("WScript.NetWork")

' Get a reference to the web service object

set WebServiceObj = GetObject("IIS://LocalHost/w3svc")

QuitOnError()

' Save the Anonymous user name and password

AnonymousUserName = WebServiceObj.AnonymousUserName

AnonymousUserPass = WebServiceObj.AnonymousUserPass

WScript.Echo "Changing the password of " & objNet.ComputerName & "\" & AnonymousUserName

QuitOnError()

Set objUser = GetObject("WinNT://" & objNet.ComputerName & "/" & AnonymousUserName)

objUser.SetPassword(AnonymousUserPass)

objUser.SetInfo

sub QuitOnError()

    if err <> 0 then

        WScript.Echo "Error: " & Hex(err) & ": " & err.description

        Wscript.Quit(1)

    end if

end sub

 

Hope this helps!

Comments

  • Anonymous
    June 29, 2007
    Wonderfull script Rakki. Thanks for sharing. I too found the iissuba.dll method to be flakey at best.