ActiveXperts Network Monitor
Monitor servers, workstations, devices and applications in your network

Quicklinks


Local Computer and NT4 User Account Scripting

Add a User to a Local Group
Change the Local Administrator Password
Create a Local User Account
Disable the Guest Account
Disable a Local User Account
Delete a Local User Account
Enable the Guest Account
List Account Expiration Dates in a Windows NT 4.0 Domain
List All the User Accounts in an NT 4.0 Domain
List Attribute Values for a Local User Account
List userFlag Values for a Local User Account
List Local Groups Using WMI
List Local User Accounts Using WMI
List User Accounts on the Local Computer
Modify the Expiration Date for a Local User Account
Modify a Local User Account Password So It Never Expires
Modify a Local User Account So It Never Expires
Require a Local User to Change His or Her Password
Verify Whether an Account Exists in a Windows NT 4.0 Domain


You can use any of the VBScript programs below in ActiveXperts Network Monitor. Click here for an explanation about how to include scripts in ActiveXperts Network Monitor.



Add a User to a Local Group


Adds a user (kenmyer) to the local Administrators group on a computer named atl-ws-01.
strComputer = "atl-ws-01"
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")

Set objUser = GetObject("WinNT://" & strComputer & "/kenmyer,user")
objGroup.Add(objUser.ADsPath)
	

Change the Local Administrator Password


Binds to the local Administrator account on the computer atl-ws-01, and changes the password for the account to 09iuy%4e.
strComputer = "atl-ws-01"
Set objUser = GetObject("WinNT://" & strComputer & "/Administrator, user")

objUser.SetPassword "09iuy%4e"
objUser.SetInfo
	

Create a Local User Account


Creates a local user account (Admin2) on a computer named atl-ws-01, and sets the password for the account to 09iu%4et.
strComputer = "atl-ws-01"
Set colAccounts = GetObject("WinNT://" & strComputer & "")
Set objUser = colAccounts.Create("user", "Admin2")
objUser.SetPassword "09iu%4et"
objUser.SetInfo
	

Disable the Guest Account


Uses the Shell object to disable the Guest account on the local computer.
Set objComputer = CreateObject("Shell.LocalMachine")
objComputer.DisableGuest(0)
	

Disable a Local User Account


Disables the local Guest account on a computer named atl-ws-01.
strComputer = "atl-ws-01"
Set objUser = GetObject("WinNT://" & strComputer & "/Guest")

objUser.AccountDisabled = True
objUser.SetInfo
	

Delete a Local User Account


Deletes the local user account Admin2 from a computer named atl-ws-01.
strComputer = "atl-ws-01"
strUser = "Admin2"

Set objComputer = GetObject("WinNT://" & strComputer & "")
objComputer.Delete "user", strUser
	

Enable the Guest Account


Uses the Shell object to enable the Guest account on the local computer.
Set objComputer = CreateObject("Shell.LocalMachine")
objComputer.EnableGuest(1)
	

List Account Expiration Dates in a Windows NT 4.0 Domain


Determines the expiration dates for all the user accounts in a Windows NT 4.0 domain named Fabrikam.
On Error Resume Next

Set objDomain = GetObject("WinNT://fabrikam,domain")
objDomain.Filter = Array("User")

For Each objUser In objDomain
   If IsNull(objUser.AccountExpirationDate) Then
       Wscript.Echo objUser.Name, "Account has no expiration date."
   Else
       Wscript.Echo objUser.Name, objUser.AccountExpirationDate
   End If
Next
	

List All the User Accounts in an NT 4.0 Domain


Returns a list of all the user accounts in a Windows NT 4.0 domain named Fabrikam.
Set objDomain = GetObject("WinNT://fabrikam,domain")
objDomain.Filter = Array("User")

For Each objUser In objDomain
    Wscript.Echo objUser.Name 
Next
	

List Attribute Values for a Local User Account


Displays mandatory and optional attributes (and their values) for a local user account named kenmyer on a computer named atl-win2k-01.
On Error Resume Next
 
strComputer = "atl-win2k-01"
Set objUser = GetObject("WinNT://" & strComputer & "/kenmyer ")
Set objClass = GetObject(objUser.Schema)
 
WScript.Echo "Mandatory properties for " & objUser.Name & ":"
For Each property in objClass.MandatoryProperties
    WScript.Echo property, objUser.Get(property)
Next
 
WScript.Echo "Optional properties for " & objUser.Name & ":"
For Each property in objClass.OptionalProperties
    WScript.Echo property, objUser.Get(property)
Next
	

List userFlag Values for a Local User Account


Accesses the userAccountControl to retrieve attribute values for the local user account kenmyer on a computer named atl-win2k-01. These attribute values include such things as account status (enabled or disabled), whether the user requires a password and, if so, whether or not that password will ever expire.
Const ADS_UF_SCRIPT = &H0001 
Const ADS_UF_ACCOUNTDISABLE = &H0002 
Const ADS_UF_HOMEDIR_REQUIRED = &H0008 
Const ADS_UF_LOCKOUT = &H0010 
Const ADS_UF_PASSWD_NOTREQD = &H0020 
Const ADS_UF_PASSWD_CANT_CHANGE = &H0040 
Const ADS_UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED = &H0080 
Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000 
Const ADS_UF_SMARTCARD_REQUIRED = &H40000 
Const ADS_UF_PASSWORD_EXPIRED = &H800000 
 
Set usr = GetObject("WinNT://atl-win2k-01/kenmyer")
flag = usr.Get("UserFlags")
 
If flag AND ADS_UF_SCRIPT Then
    Wscript.Echo "Logon script will be executed."
Else
    Wscript.Echo "Logon script will not be executed."
End If
 
If flag AND ADS_UF_ACCOUNTDISABLE Then
    Wscript.Echo "Account is disabled."
Else
    Wscript.Echo "Account is not disabled."
End If
 
If flag AND ADS_UF_HOMEDIR_REQUIRED Then
    Wscript.Echo "Home directory required."
Else
    Wscript.Echo "Home directory not required."
End If
 
If flag AND ADS_UF_PASSWD_NOTREQD Then
    Wscript.Echo "Password not required."
Else
    Wscript.Echo "Password required."
End If
 
If flag AND ADS_PASSWORD_CANT_CHANGE Then
    Wscript.Echo "User cannot change password."
Else
    Wscript.Echo "User can change password."
End If
 
If flag AND ADS_UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED Then
    Wscript.Echo "Encrypted password allowed."
Else
    Wscript.Echo "Encrypted password not allowed."
End If
 
If flag AND ADS_UF_DONT_EXPIRE_PASSWD Then
    Wscript.Echo "Password does not expire."
Else
    Wscript.Echo "Password expires."
End If
 
If flag AND ADS_UF_SMARTCARD_REQUIRED Then
    Wscript.Echo "Smartcard required for logon."
Else
    Wscript.Echo "Smart card not required for logon."
End If
 
If flag AND ADS_UF_PASSWORD_EXPIRED Then
    Wscript.Echo "Password has expired."
Else
    Wscript.Echo "Password has not expired."
End If
	

List Local Groups Using WMI


Returns information about the local groups found on a computer.
On Error Resume Next

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_Group  Where LocalAccount = True")

For Each objItem in colItems
    Wscript.Echo "Caption: " & objItem.Caption
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Domain: " & objItem.Domain
    Wscript.Echo "Local Account: " & objItem.LocalAccount
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "SID: " & objItem.SID
    Wscript.Echo "SID Type: " & objItem.SIDType
    Wscript.Echo "Status: " & objItem.Status
    Wscript.Echo
Next
	

List Local User Accounts Using WMI


Returns information about the local user accounts found on a computer.
On Error Resume Next

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_UserAccount Where LocalAccount = True")

For Each objItem in colItems
    Wscript.Echo "Account Type: " & objItem.AccountType
    Wscript.Echo "Caption: " & objItem.Caption
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Disabled: " & objItem.Disabled
    Wscript.Echo "Domain: " & objItem.Domain
    Wscript.Echo "Full Name: " & objItem.FullName
    Wscript.Echo "Local Account: " & objItem.LocalAccount
    Wscript.Echo "Lockout: " & objItem.Lockout
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Password Changeable: " & objItem.PasswordChangeable
    Wscript.Echo "Password Expires: " & objItem.PasswordExpires
    Wscript.Echo "Password Required: " & objItem.PasswordRequired
    Wscript.Echo "SID: " & objItem.SID
    Wscript.Echo "SID Type: " & objItem.SIDType
    Wscript.Echo "Status: " & objItem.Status
    Wscript.Echo
Next
	

List User Accounts on the Local Computer


Returns a list of all the user accounts found on the local computer.
Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName

Set colAccounts = GetObject("WinNT://" & strComputer & "")
colAccounts.Filter = Array("user")

For Each objUser In colAccounts
    Wscript.Echo objUser.Name 
Next
	

Modify the Expiration Date for a Local User Account


Binds to a local user account (kenmyer) on a computer named atl-win2k-01, and configures the account to expire on March 1, 2005.
strComputer = "atl-win2k-01"
Set objUser = GetObject("WinNT://" & strComputer & "/kenmyer")

objUser.AccountExpirationDate = #03/01/2005# 
objUser.SetInfo
	

Modify a Local User Account Password So It Never Expires


Binds to a local user account on a computer named atl-win2k-01, and configures the account password so it never expires.
Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000
 
strDomainOrWorkgroup = "Fabrikam"
strComputer = "atl-win2k-01"
strUser = "KenMeyer"
 
Set objUser = GetObject("WinNT://" & strDomainOrWorkgroup & "/" & _
    strComputer & "/" & strUser & ",User")
 
objUserFlags = objUser.Get("UserFlags")
objPasswordExpirationFlag = objUserFlags OR ADS_UF_DONT_EXPIRE_PASSWD
objUser.Put "userFlags", objPasswordExpirationFlag 
objUser.SetInfo
	

Modify a Local User Account So It Never Expires


Binds to the local user account on a computer named atl-win2k-01, and configures the account so that it never expires.
Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000

strComputer = "atl-win2k-01"
Set objUser = GetObject("WinNT://" & strComputer & "/kenmyer")

objUserFlags = objUser.Get("UserFlags")
objPasswordExpirationFlag = objUserFlags OR ADS_UF_DONT_EXPIRE_PASSWD
objUser.Put "userFlags", objPasswordExpirationFlag 
objUser.SetInfo
	

Require a Local User to Change His or Her Password


Binds to a local user account on the computer named atl-win2k-01, and configures the account so that the user (kenmyer) must change his password the next time he logs on.
strComputer = "atl-win2k-01"
Set objUser = GetObject("WinNT://" & strComputer & "/kenmyer")

objUser.Put "PasswordExpired", 1
objUser.SetInfo
	

Verify Whether an Account Exists in a Windows NT 4.0 Domain


Checks to see if a user account (kenmyer) exists in a Windows NT 4.0 domain named Fabrikam.
strUserName = "kenmyer"
Set objDomain = GetObject("WinNT://fabrikam")
objDomain.Filter = Array("user")
intFound = 0

For Each User In objDomain
    If lcase(User.Name) = lcase(strUserName) Then
        intFound = 1   
    End If    
Next

If intFound = 1 Then
    WScript.Echo "The " & strUserName & " account already exists."
Else
    WScript.Echo "The " & strUserName & " account does not exist in the domain."
End If