'*** ADD A COMMENT TO COMPUTER ACCOUNT *** 'Alan Kaplan, for VA VISN 6 '8/24/01 'www.akaplan.com/tools.html 'This script adds comment for a Computer in domain 'Requires ADSI on workstation running script Option Explicit Dim WshShell, key, key2 Dim Major, Minor, Ver, message,message1,title1 dim DName, title, text1, Exname,result dim servername, newpassword, dspath dim objDomain, adscomputer,mydomain,newcomment Set WshShell = WScript.CreateObject("WScript.Shell") 'get resource domain name as default search string within logon domain key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\Currentversion\Winlogon\CachePrimaryDomain" mydomain = WshShell.RegRead (key) ' Define dialog box variables. message = "Please Enter Domain where computer account resides" title = "What domain" 'get domain name, domain default dname = InputBox(message, title, mydomain) '****** optional edit ************ Exname = "computername" 'Example display servername for domain '**************************** 'Remark out next line AFTER you know workstation 'is properly configured to speed execution ... SysTest 'set the servername to 1st argument passed to script On Error resume next servername = WScript.Arguments(0) if err <> 0 then ' No servername err.clear on error goto 0 ' Define dialog box variables. Message = "You must have adequate security to run this script!" &vbCRLF _ &vbCRLF & "Please enter a computer within " & Ucase(dname) & " domain." Title = "Select Computer" Text1 = "Canceled" servername = InputBox(Message, Title, Exname) If servername = "" Then 'Canceled by the user WScript.Quit End If End if err.clear on error goto 0 ' Define dialog box variables. Message = "Please enter a comment for " & servername Title = "Add Workstation comment" Text1 = "Canceled" newcomment = InputBox(Message, Title) If newcomment = "" Then 'Canceled by the user WScript.Quit End If err.clear on error resume next 'Thanks to Bob Wells at Microsoft for finding how to get the appropriate 'DS path for this DSPath = "WinNT://" & DName & "/" & servername & "/LanManServer,FileService" Set adscomputer = GetObject(DSPath) if err <> 0 then err.clear on error goto 0 ' Define dialog box variables. Message = Ucase(dname & "\" & servername) & " not found, or insufficient authority for change." Title = "Cannot Access Computer Account" WshShell.Popup message,0,title,vbcritical WScript.Quit End If 'First line of results message message = "Old Comment: " & adsComputer.Description &vbcrlf adsComputer.Description = newcomment adsComputer.SetInfo adsComputer.GetInfo if err = 0 then message = message & "New: " & adsComputer.Description Else message = message & "Failed to set comment" &vbcrlf end if WshShell.Popup message,0,"Comment Status",vbInformation WScript.Quit 'End 'subroutine to test for ADSI and WSH 5.5 Sub SysTest() ' WSH version tested Major = (ScriptEngineMinorVersion()) Minor = (ScriptEngineMinorVersion())/10 Ver = major + minor 'Need version 5.5 If ver < 5.5 then message = "You have WScript Version " & ver & ". Please load Version 5.5 or later." 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 '**** Script Ends ***