Created
October 2, 2011 17:43
-
-
Save slacker/1257689 to your computer and use it in GitHub Desktop.
Disable local user accounts found in text file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' Disable local users that are a member of a list of usernames | |
' You can output to a file by the following command: | |
' | |
' cscript disableusers.vbs > c:\output.txt | |
' File containing the users to disable, 1 per line | |
Set objFSO = CreateObject("Scripting.FileSystemObject") | |
Set objFile = objFSO.OpenTextFile("c:\xfer\userstodisable.txt", ForReading) | |
' Build an array of users to disable | |
Const ForReading = 1 | |
Dim arrUsersToDisable() | |
i = 0 | |
Do Until objFile.AtEndOfStream | |
Redim Preserve arrUsersToDisable(i) | |
arrUsersToDisable(i) = objFile.ReadLine | |
i = i + 1 | |
Loop | |
objFile.Close | |
' Helper function to determine if a value is present in an array | |
Function IsInArray(strIn, arrCheck) | |
Dim bFlag | |
bFlag = False | |
If IsArray(arrCheck) AND Not IsNull(strIn) Then | |
Dim i | |
For i = 0 to UBound(arrCheck) | |
If LCase(arrcheck(i)) = LCase(strIn) Then | |
bFlag = True | |
End If | |
Next | |
End If | |
IsInArray = bFlag | |
End Function | |
Set objShell = CreateObject("Wscript.Shell") | |
Set objNetwork = CreateObject("Wscript.Network") | |
strComputer = objNetwork.ComputerName | |
Set colAccounts = GetObject("WinNT://" & strComputer & "") | |
colAccounts.Filter = Array("user") | |
Message = Message & "Local User accounts:" & vbCrLf & vbCrLf | |
For Each objUser In colAccounts | |
If IsInArray(objUser.Name,arrUsersToDisable) Then | |
Message = Message & objUser.Name | |
If objUser.AccountDisabled = TRUE then | |
Message = Message & " is currently disabled" & vbCrLf | |
Else | |
Message = Message & " has been disabled" & vbCrLf | |
objUser.AccountDisabled = True | |
objUser.SetInfo | |
End if | |
End If | |
Next | |
wscript.echo(Message) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment