'***** REMOVE LOCAL USER ACCOUNT FROM ALL SYSTEMS IN DOMAIN **** 'Alan Kaplan 'www.akaplan.com/tools.html 'Last Revision 8/26/01 option explicit Dim usr, user, userobj,wshshell dim key,key2,major,minor,ver Dim regEx, retVal,result,server,serverlist,slist,slist2 Dim cont,dnameobj, domain, RDname, quote, command dim logfile,comma,newline,message,cdname,title,pwage,lldate dim fso,appendout,ofile dim example, ntreskit, name2kill '*****Mandatory Edit *************** 'ntreskit is required only if you need to reboot ... see below 'ntreskit = "\\pathname\ntreskit$" logfile = "c:\deluser.csv" 'Name of log file. Can open in Excel delimiter is "," name2kill = "genericacct" 'Name of account to remove from local workstation '*****Optional Edit *********************** 'message format helpers.. newline = "" comma = "," quote = chr(34) Set WshShell = WScript.CreateObject("WScript.Shell") 'Test for ADSI and current WSH SysTest 'get resource domain name as default search string within logon domain key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\Currentversion\Winlogon\CachePrimaryDomain" CDname = WshShell.RegRead (key) 'on error resume next ' Define dialog box variables. message = "Please Enter Domain Name" title = "Domain to list" 'get domain name, domain default RDname = InputBox(message, title, CDName) ' Evaluate the user input. If RDname = "" Then ' Canceled by the user WScript.quit End If 'Make sure running Cscript. Mostly G. Born code... If (Not IsCScript()) Then 'If not CScript, re-run with cscript... WshShell.Run "CScript.exe " & WScript.ScriptFullName WScript.Quit '...and stop running as WScript End If On Error resume next 'Remark out next line to speed execution AFTER you know workstation 'is properly configured... SysTest dim rserver,rgroup,dgroup dim objGroup, objDGroup, message1 dim Username, newpassword, dspath dim objDomain, objUser public LAccount public LPass 'setup log dim prompt prompt = FALSE Const ForAppend = 8 set fso = CreateObject("Scripting.FileSystemObject") set AppendOut = fso.OpenTextFile(logfile, ForAppend, True) appendout.writeline "Computer,Comment,Result,"&date 'Main Routine dim computer on error goto 0 dnameobj = "WinNT://" & RDname 'attach to server Set cont = GetObject(dnameobj) cont.Filter = Array("computer") For Each computer In cont rserver = computer.name deluser name2kill Next 'Done. open file with associated app, Excel if installed. command = "cmd.exe /c start " & logfile WshShell.Run command wscript.quit 'The end 'Delete a local user subroutine sub DelUser (Username) on error resume next 'Bind to the computer to see if you can connect Set objDomain = GetObject("WinNT://" & Rserver & ",computer") If (Err <> 0) Then EchoandLog Rserver & ", could not be reached, Failure" Exit Sub End If on error goto 0 'Fail on errors... Wscript.echo vbCrLF & "Sending commands to " & Rserver dim UserParent on error resume next err.clear Set objUser = GetObject("WinNT://" & Rserver & "/" & username & ",user") set userParent = GetObject(objUser.Parent) userParent.Delete "user", ObjUser.Name select case err.number case 0 EchoAndLog RServer & ", Deleted " & Username & ", Success" 'Optional --- send user a message and reboot using NTreskit shutdown ' message = username & " account deleted. You must logon with your own username after reboot." ' command = ntreskit & "\shutdown \\" & Rserver & " /r /t:300 " & quote & message & quote & " /y /c" ' WshShell.Run command,0,true case 424 EchoAndLog RServer & ", No accounts exists for " & Username & ", Success" case else EchoAndLog RServer & ", Error deleting " & Username &", Failure" End Select set objUser = Nothing set objParent = Nothing end sub Sub SysTest() on error resume next ' WSH version tested Major = (ScriptEngineMinorVersion()) Minor = (ScriptEngineMinorVersion())/10 Ver = major + minor 'Need version 5.5 If err.number or ver < 5.5 then message = "You have must load Version 5.5 (or later) of Windows Script Host" &vbCrLf End If 'Test for ADSI err.clear key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components\{E92B03AB-B707-11d2-9CBD-0000F87A369E}\version" key2 = WshShell.RegRead (key) if err <> 0 then message = message & "ADSI must be installed on local workstation to continue" & vbCrLf WshShell.Popup message,0,"Workstation Setup Error",vbInformation WScript.Quit End if End Sub 'Function to test whether host CScript.exe. Function IsCScript() If (InStr(UCase(WScript.FullName), "CSCRIPT") <> 0) Then IsCScript = True Else IsCScript = False End If End Function Sub EchoAndLog (message) 'Echo output and write to log Wscript.Echo message AppendOut.WriteLine message End Sub '***** Script ends ****