| 关键词: nbsp intRow pc Wscript Error colSettings strExcelPath adoRecordset Then Set |
原来代码在 http://www.rlmueller.net/Programs/Inventory2.txt ,可惜它的要调用excel组件,而且还会弹出ie对话框。花了一点时间修改了一下,可以直接保存成html了,方便用于入侵。。由于我用的是数组pc(65535,10),如果内网过大(>65535?,呵呵)请小心使用,只测试过域管理员权限,其它权限未测,应当也是可以的。 程序代码 ' Inventory2.vbs'code by http://www.rlmueller.net/Programs/Inventory2.txt ; modify by lcxOption ExplicitDim strComputer, strDNDim objShell, objFSO, strTemp, strTempFile, fileSDim objRootDSE, strRootDomain, adoConnection, adoCommand, strQueryDim adoRecordset, strAttributesDim objRemote, strRoleDim strExcelPath, intRow, pc(65535,10)Dim colSettings, objOS, objComputerDim objFixDim blnFlag, strPrevious, strStatusDim sHTMLConst ADS_CHASE_REFERRALS_SUBORDINATE = &H20If (Wscript.Arguments.Count <> 1) Then Wscript.Echo "Argument <FileName> required. For example" & vbCrLf _ & "cscript Inventory.vbs ""c:\MyFolder\Inventory.html""" Wscript.QuitEnd If' Spreadsheet file name to be created.strExcelPath = Wscript.Arguments(0)blnFlag = TrueSet objShell = CreateObject("Wscript.Shell")On Error Resume NextSet objRootDSE = GetObject("LDAP://RootDSE")If (Err.Number <> 0) Then On Error GoTo 0 Set objShell = Nothing Wscript.Echo "Domain not found, program aborted." Wscript.Echo "You may not be logged into a domain." Wscript.QuitEnd IfOn Error GoTo 0strRootDomain = objRootDSE.Get("rootDomainNamingContext")pc(0,0) = "sAMAccountName"pc(0,1)="distinguishedName"pc(0,2)="WMI"pc(0,3)="# of OS's"pc(0,4)= "OS Caption"pc(0,5)="OS Version"pc(0,6)= "OS Service Pack"pc(0,7)= "# of Hot Fixes"pc(0,8)= "Hot Fix ID"pc(0,9)= "# of Computer Systems"pc(0,10)="Computer Role"sHTML = "<table width='100%' border='1' cellspacing='0' cellpadding='0'>"Set objFSO = CreateObject("Scripting.FileSystemObject")Set fileS=objFSO.opentextfile(strExcelPath,2,true)fileS.writeline sHTML&vbcrlf& "<tr><td>"&pc(0,0)&"</td><td>"&pc(0,1)&"</td><td>"&pc(0,2)&"</td><td>"&pc(0,3)_&"</td><td>"&pc(0,4)&"</td><td>"&pc(0,5)&"</td><td>"&pc(0,6)&"</td><td>"&pc(0,7)_&"</td><td>"&pc(0,8)&"</td><td>"&pc(0,9)&"</td><td>"&pc(0,10)&"</td></tr>"' Use ADO to search Active Directory for all computers.Set adoCommand = CreateObject("ADODB.Command")Set adoConnection = CreateObject("ADODB.Connection")adoConnection.Provider = "ADsDSOObject"adoConnection.Open = "Active Directory Provider"adoCommand.ActiveConnection = adoConnection' Retrieve attributes.strAttributes = "sAMAccountName,distinguishedName"strQuery = "<LDAP://" & strRootDomain _ & ">;(ObjectCategory=computer);" & strAttributes & ";subtree"adoCommand.CommandText = strQueryadoCommand.Properties("Page Size") = 100adoCommand.Properties("Timeout") = 30adoCommand.Properties("Cache Results") = FalseadoCommand.Properties("Chase Referrals") = _ ADS_CHASE_REFERRALS_SUBORDINATESet adoRecordset = adoCommand.Execute' Specify temporary file to save ping results.strTemp = objShell.ExpandEnvironmentStrings("%TEMP%")strTempFile = strTemp & "\RunResult.tmp"' Enumerate computer objects.intRow = 2Do Until adoRecordset.EOF strComputer = adoRecordset.Fields("sAMAccountName").Value ' Remove trailing "$". strComputer = Left(strComputer, Len(strComputer) - 1) pc(intRow, 0)=strComputer strDN = adoRecordset.Fields("distinguishedName").Value pc(intRow, 1)=strDNstrPrevious = strComputerIf (blnFlag = False) Then If (Err.Number <> 0) Then On Error GoTo 0 Wscript.Echo "The path may be invalid." strExcelPath = "" End If On Error GoTo 0 adoRecordset.Close adoConnection.Close If (objFSO.FileExists(strTempfile) = True) Then objFSO.DeleteFile(strTempFile) End If Set objRootDSE = Nothing Set adoCommand = Nothing Set adoConnection = Nothing Set adoRecordset = Nothing Set objRemote = Nothing Set objShell = Nothing Wscript.Echo "Program Aborted" Wscript.Echo "Computers documented: " & (intRow - 1) If (strExcelPath <> "") Then Wscript.Echo "See spreadsheet " & strExcelPath End If Wscript.Quit End If ' Ping computer to see if online. If (IsConnectible(strComputer, 1, 750) = True) Then ' Connect to computer with WMI. On Error Resume Next Set objRemote = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" _ & strComputer & "\root\cimv2") If (Err.Number <> 0) Then On Error GoTo 0 pc(intRow, 2)="WMI Not Installed" strStatus = " no WMI" Else On Error GoTo 0 pc(intRow, 2)="WMI Installed" On Error Resume Next Set colSettings = objRemote.ExecQuery _ ("Select * FROM Win32_OperatingSystem") If (Err.Number <> 0) Then On Error GoTo 0 pc(intRow, 3)="Failed" Else On Error GoTo 0 pc(intRow, 3)=colSettings.Count For Each objOS In colSettings pc(intRow, 4)=objOS.Caption pc(intRow, 5)=objOS.Version pc(intRow, 6)=_ objOS.ServicePackMajorVersion & "." _ & objOS.ServicePackMinorVersion Next Set objOS = Nothing End If On Error Resume Next Set colSettings = objRemote.ExecQuery _ ("Select * FROM Win32_QuickFixEngineering") If (Err.Number <> 0) Then On Error GoTo 0 pc(intRow, 7)= "Failed" Else On Error GoTo 0 pc(intRow, 7)= colSettings.Count For Each objFix In colSettings pc(intRow, 8)=objFix.HotFixID Next Set objFix = Nothing End If On Error Resume Next Set colSettings = objRemote.ExecQuery _ ("Select * FROM Win32_ComputerSystem") If (Err.Number <> 0) Then On Error GoTo 0 pc(intRow, 9)="Failed" Else On Error GoTo 0 pc(intRow, 9)=colSettings.Count For Each objComputer In colSettings Select Case objComputer.DomainRole Case 0 strRole = "Standalone Workstation" Case 1 strRole = "Member Workstation" Case 2 strRole = "Standalone Server" Case 3 strRole = "Member Server" Case 4 strRole = "Backup Domain Controller" Case 5 strRole = "Primary Domain Controller" Case Else strRole = "Unknown" End Select pc(intRow, 10)=strRole Next Set objComputer = Nothing End If Set colSettings = Nothing strStatus = " documented" End If Else pc(intRow, 2)="Computer Not Found" strStatus = " not on line" End IffileS.write "<tr><td>"&pc(intRow, 0)&"</td><td>"&pc(intRow, 1)&"</td><td>"&pc(intRow, 2)&"</td><td>"&pc(intRow, 3)&"</td><td>"_&pc(intRow, 4)&"</td><td>"&pc(intRow, 5)&"</td><td>"&pc(intRow, 6)&"</td><td>"&pc(intRow, 7)_&"</td><td>"&pc(intRow, 8)&"</td><td>"&pc(intRow, 9)&"</td><td>"&pc(intRow, 10)&"</td></tr>" intRow = intRow + 1 adoRecordset.MoveNextLoopadoRecordset.ClosefileS.writeline "</table>"' Save spreadsheet and close the workbook.On Error Resume NextIf (Err.Number <> 0) Then On Error GoTo 0 Wscript.Echo "Spreadsheet could not be saved as " & strExcelPath Wscript.Echo "The path may be invalid." strExcelPath = ""End IfOn Error GoTo 0adoConnection.CloseIf (objFSO.FileExists(strTempfile) = True) Then objFSO.DeleteFile(strTempFile)End IfSet objRootDSE = NothingSet adoCommand = NothingSet adoConnection = NothingSet adoRecordset = NothingSet objRemote = NothingSet objFSO = NothingSet objShell = NothingWscript.Echo "Done"Wscript.Echo "Documented " & (intRow - 2) & " computers"If (strExcelPath <> "") Then Wscript.Echo "See spreadsheet " & strExcelPathEnd IfFunction IsConnectible(ByVal strHost, ByVal intPings, ByVal intTO) ' Returns True if strHost can be pinged. ' Based on a program by Alex Angelopoulos and Torgeir Bakken. Dim objFile, strResults If (intPings = "") Then intPings = 2 End If If (intTO = "") Then intTO = 750 End If Const OpenAsDefault = -2 Const FailIfNotExist = 0 Const ForReading = 1 objShell.Run "%comspec% /c ping -n " & intPings & " -w " & intTO _ & " " & strHost & ">" & strTempFile, 0, True Set objFile = objFSO.OpenTextFile(strTempFile, ForReading, _ FailIfNotExist, OpenAsDefault) strResults = objFile.ReadAll objFile.Close Select Case InStr(strResults, "TTL=") Case 0 IsConnectible = False Case Else IsConnectible = True End SelectEnd Function |
|
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系
[邮箱地址] 删除
|