iT邦幫忙

0

查詢軟體安裝與本機所有群組及群組內使用者列表

  • 分享至 

  • xImage

請教各位前輩
小弟在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
Jesse HO iT邦好手 1 級 ‧ 2019-04-29 02:23:41 檢舉
powershell may be easier
HTH

#software installed
https://devblogs.microsoft.com/scripting/use-powershell-to-find-installed-software/

#hardware infomation
https://community.spiceworks.com/scripts/show/1831-get-computer-system-and-hardware-information

#localgroup all detail (cation your powershell version)
foreach ($Group in ((Get-LocalGroup -name *).name))
{
if ((Get-LocalGroupmember $Group).count -eq 0) {
$Group+"`t`t"
}
else
{
Get-localgroupmember -Name $Group|select -Property @{n='Group';e={$Group}},@{n='Name';e={$_.Name}},@{n='PrincipalSource';e={$_.PrincipalSource}}
}
#$X|ft -AutoSize
}
謝謝何必問好手的回覆。
這邊因為有遇到一些問題,所以沒辦法用PowerShell的命令執行
所以只能從原本的VBS想辦法..................
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

0
sleeping_fish
iT邦新手 3 級 ‧ 2019-04-29 09:40:02

我們公司是有裝防毒軟體(卡巴斯基)企業版,其中內容有就使用者明細 及 電腦內所安裝的軟體清單。然後可以匯出明細,如果你們有裝企業版的防毒軟體,也可以順便檢查一下優。

敝司的防毒做不到這一點,只好用VBS來看看是否可以做的到。

0
vekaur
iT邦新手 5 級 ‧ 2020-06-16 17:04:35

請教shadowpeople此題解了嗎?
另外,我將您的語法儲存成vbs執行卻有錯誤,是否哪些需要修改
https://ithelp.ithome.com.tw/upload/images/20200616/20042968HLki82Qx0F.jpg

抱歉,我可以提供現在的版本給您,如果方便請提供 Email。

我要發表回答

立即登入回答