請教各位前輩
小弟在IT幫內看到下述一段VBScript程式可以將查詢電腦硬體資訊與軟體安裝的功能。https://ithelp.ithome.com.tw/questions/10039579
不知道有沒有高手可以在這個程式中
再加入列出本機所有群組以及群組中包含的使用者清單
下述為程式樣本。
<pre class="c" name="code">
Const HKEY_LOCAL_MACHINE = &H80000002
Const FOR_WRITING = 2
Const ForReading = 1
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set oList = objFso.OpenTextFile("servers.txt",ForReading)
Do While Not oList.AtEndOfStream
strComputername = oList.ReadLine
If Left(strComputername,1) <> ";" Then
Output ("==========================================================")
If HostOnline(strComputername) = True Then
Output(strComputername)
Inventory(strComputername)
Output ("==========================================================")
Else
Output(strComputername & " is down, skipping..")
End If
End If
Loop
'==========================================================================
Function Inventory(strComputername)
On Error Resume Next
Set oTextFile = objFso.OpenTextFile(strComputername & ".txt", FOR_WRITING, TRUE)
'oTextFile.WriteLine strComputername
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputername & "\root\cimv2")
Set colOSes = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objOS in colOSes
oTextFile.WriteLine "Computer Name: " & objOS.CSName
oTextFile.WriteLine "Caption: " & objOS.Caption
oTextFile.WriteLine "Version: " & objOS.Version
oTextFile.WriteLine "Build Number: " & objOS.BuildNumber
oTextFile.WriteLine "Build Type: " & objOS.BuildType
oTextFile.WriteLine "OS Type: " & objOS.OSType
oTextFile.WriteLine "Other Type Description: " & objOS.OtherTypeDescription
oTextFile.WriteLine "Service Pack: " & objOS.ServicePackMajorVersion & "." & objOS.ServicePackMinorVersion
Next
Set colProcs = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
For Each objItem in colProcs
oTextFile.WriteLine "Number of Processors: " & objItem.NumberOfProcessors
Next
oTextFile.WriteLine vbCrLf & "Applications:"
Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputername & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys
strSubKeyPath = strKeyPath & "\" & subkey
strString = "DisplayName"
objReg.GetStringValue HKEY_LOCAL_MACHINE, strSubKeyPath, strString, strDisplayName
strString = "DisplayVersion"
objReg.GetStringValue HKEY_LOCAL_MACHINE, strSubKeyPath, strString, strDisplayVersion
strDisplayName=Trim(strDisplayName)
strDisplayVersion=Trim(strDisplayVersion)
If strDisplayName <> "" And strDisplayVersion <> "" Then
Output (strDisplayName & " " & strDisplayVersion)
oTextFile.WriteLine strDisplayName & " " & strDisplayVersion
End If
Next
objTextFile.close
End Function
Function Output(sOutput)
WScript.echo Date() & " " & Time() & vbTab & sOutput
End Function
Function HostOnline(strComputername)
Set sTempFolder = objFso.GetSpecialFolder(TEMPFOLDER)
sTempFile = objFso.GetTempName
sTempFile = sTempFolder & "\" & sTempFile
objShell.Run "cmd /c ping -n 2 -l 8 " & strComputername & ">" & sTempFile,0,True
Set oFile = objFso.GetFile(sTempFile)
set oTS = oFile.OpenAsTextStream(ForReading)
do while oTS.AtEndOfStream <> True
sReturn = oTS.ReadLine
if instr(sReturn, "Reply")>0 then
HostOnline = True
Output("Computer " & strComputername & " is alive!")
Exit Do
End If
Loop
ots.Close
oFile.delete
End Function
oList.Close
Set objReg = Nothing
Set objFso = Nothing
我們公司是有裝防毒軟體(卡巴斯基)企業版,其中內容有就使用者明細 及 電腦內所安裝的軟體清單。然後可以匯出明細,如果你們有裝企業版的防毒軟體,也可以順便檢查一下優。
請教shadowpeople此題解了嗎?
另外,我將您的語法儲存成vbs執行卻有錯誤,是否哪些需要修改