'***** GetRegandPageSize Script begins *** 'Alan Kaplan for VISN 6 'akaplan@msdinc.com www.msdinc.com 'also alan@akaplan.com 'Last revision 8/20/01 'This program gets the max registry size and page file size for all workstations 'and dumps information into a spreadsheet 'Requires RegObj.dll from Microsoft option explicit Dim wshshell, objreg,objcontainer,objremote,objregkey,dnameobj dim key,key2,major,minor,ver,quote, command,regsize dim rdname, colpcs,rserver dim logfile,comma,message,cdname,title dim fso,appendout,ofile,pstatus,rstatus,pagesize 'message format helpers.. comma = "," quote = chr(34) Set WshShell = WScript.CreateObject("WScript.Shell") '*********** OPTIONAL EDIT HERE *************************** '*** Name of log file. UNC path is okay. Leave extension as CSV '*** to have it opened by Excel. Change to TXT '*** if Excel not loaded on workstation running script logfile = "c:\RegPageSize.csv" '*********** EDIT ENDS *************************** 'Test for ADSI and current WSH, host set to Cscript, regobj installed 'Do not comment out! SysTest 'get resource domain name as default search string within logon domain key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\Currentversion\Winlogon\CachePrimaryDomain" RDname = WshShell.RegRead (key) ' Define dialog box variables. message = "You must have rights to query the remote NT/Win2K workstation's registry for this to work!"&vbCrLf &vbCrLf message = message & "You will overwrite the logfile " & logfile & " if it exists." &vbCrLf & vbCrLf message = message & "Please enter domain name to search:" title = "Get Max Registry Size" 'get resource domain name, domain default CDName = InputBox(message, title, RDName) ' Evaluate the user input. If CDName = "" Then ' Canceled by the user WScript.quit End If const root = "\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\" const value1 = "RegistrySizeLimit" const root2 = "\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\" const value2 = "PagingFiles" 'on error resume next 'setup log 'logfile is set to append. Const ForAppend = 8 set fso = CreateObject("Scripting.FileSystemObject") 'delete old log if (fso.FileExists(logfile))then set oFile = fso.GetFile (logfile) oFile.Delete end if 'create header for log set AppendOut = fso.OpenTextFile(logfile, ForAppend, True) appendout.writeline "Computername, Regsize MB, Pagesize Info, Comments" 'run getinfo on all computers in resource domain 'This should work with with Win2k Active directory per docs.... DnameObj = "WinNT://" & cdname 'Case counts here! WshShell.Popup "Be patient, this may take some time",3,"Ready to Query Domain",64 Set objContainer=GetObject(DnameObj) objContainer.Filter=Array("computer") For Each colPCs in objContainer rserver = "\\" & colPCs.Name GetInfo Next 'Done. open file with associated app, Excel if installed. command = "cmd.exe /c start " & logfile WshShell.Run command wscript.quit 'The end 'Functions and Subroutines Sub GetInfo() 'Main Routine regsize = "" pagesize = "" on error resume next ' *** Connect to remote registry *** err.clear Set objRemote = objReg.RemoteRegistry(rserver) set objRegkey = objRemote.RegKeyFromString(root) 'if fails tell why if err <> 0 then EchoAndLog colPCs.Name & ",Not Found" Exit sub End if err.clear 'and read values regsize = objRegKey.Values(value1).Value 'if fails tell why if err <> 0 then rstatus = "regsize read failed" Else rstatus = "RegSize success" regsize = round(((regsize/1024)/1024),0) End If ' *** Connect to remote registry again *** err.clear set objRegkey = objRemote.RegKeyFromString(root2) 'and read values pagesize = objRegKey.Values(value2).Value 'if fails tell why if err <> 0 then pstatus = "Pagefile read failed" Else pstatus = "PageSize success" on error goto 0 EchoAndLog colPCs.Name & "," & rstatus & " " & pstatus & "," & regsize & "," & cstr(pagesize) End If End Sub Sub EchoAndLog (message) 'Subroutine to echo to screen and write to log Wscript.Echo message 'appendout is defined as part of log setup AppendOut.WriteLine message 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",vbCritical WScript.Quit End if ' Create object reference to Regobj.dll. err.clear on error resume next Set objReg = WScript.CreateObject("RegObj.Registry") 'if fails tell why if err <> 0 then message = "You must have regobj.dll in c:\winnt\system32" &_ " and registered using regsvr32 for this to work" WshShell.Popup message,0,"Workstation Setup Error",vbCritical WScript.Quit End if 'Test whether the host is CScript.exe. 'G. Born code... If IsBatch = "TRUE" Then If (Not IsCScript()) Then message = "You must set default host to cscript to run as a batch." &vbcrlf &_ "Use the command wscript //h:cscript" 'popup closes to avoid desktop hell WshShell.Popup message,3,"Workstation Setup Error",vbCritical WScript.Quit ' Terminate script. End If End if End Sub Function IsCScript() ' Check whether CScript.exe is the host. If (InStr(UCase(WScript.FullName), "CSCRIPT") <> 0) Then IsCScript = True Else IsCScript = False End If End Function '**** Script Ends