问题描述
- 怎样读取ActiveDirectory域中的所有电脑的硬件信息
- 一般情况都是使用LDAP读取AD服务器中用户信息,现在公司需要实现把域中所有电脑的硬件信息(例如硬盘、cpu型号、内存大小)搜集起来,不知道谁有没有过这方面的经验,给点意见,谢谢!
解决方案
On Error Resume Next
temp=0
set wshshell=wscript.createobject(""wscript.shell"")
wshshell.run (""%comspec% /c regsvr32 /s scrrun.dll"")0True
wshshell.run (""%comspec% /c sc config winmgmt start= auto"")0True
wshshell.run (""%comspec% /c net start winmgmt"")0
Set WshNetwork = WScript.Createobject(""WScript.Network"")
computername=WshNetwork.ComputerName
set fso=createobject(""scripting.filesystemobject"")
tempfilter=""你的服務器地址hard_info""& computername &"".txt""
set tempfile=fso.createtextfile(tempfilter)
strComputer = "".""
Set objWMIService = Getobject(""winmgmts:"" & strComputer & ""rootcimv2"")
set board =objwmiservice.execQuery(""select * from win32_baseboard"")
for each item in board
board2= item.Product
next
'CPU
set cpu =objwmiservice.execQuery(""select * from win32_processor"")
for each item in cpu
cpu2= item.Name
next
Set colItems = objWMIService.ExecQuery(""Select * from Win32_PhysicalMemory""48)
For Each objItem in colItems
a=objitem.capacity/1048576
temp=temp+objitem.capacity
n=n+1
Next
memory=temp/1048576
if n=1 then
memory2= n & ""條"" &a& ""M""
else
memory2= n & ""條"" &a& ""M""&"" 合計""&memory&""M""
end if
'sound
set sound =objwmiservice.execQuery(""select * from win32_SoundDevice""48)
for each item in sound
sound2= item.ProductName
next
'OS
set OS =objwmiservice.execQuery(""select * from win32_OperatingSystem""48)
for each item in OS
OS2= item.Caption & item.Version
next
Set objWMIService = GetObject(""winmgmts:"" & strComputer & ""rootcimv2"")
Set colItems = objWMIService.ExecQuery(""Select * from Win32_CDROMDrive"" 48)
J = 0
For Each objItem In colItems
If J = 0 Then CDROM2 = (Trim(objItem.Name)) Else CDROM3 = (Trim(objItem.Name))
J = J + 1
Next
Set colItems = objWMIService.ExecQuery(""Select * from Win32_NetworkAdapter"" 48)
J = 0
For Each objItem In colItems
If J = 0 Then lan1= (Trim(objItem.ProductName)) Else lan2= (Trim(objItem.ProductName))
J = J + 1
Next
Set colItems = objWMIService.ExecQuery(""Select * from Win32_NetworkAdapter"" 48)
J = 0
For Each objItem In colItems
If J = 0 Then lan3= (Trim(objItem.MACAddress)) Else lan4= (Trim(objItem.MACAddress))
J = J + 1
Next
Set colItems = objWMIService.ExecQuery(""Select * from Win32_DiskDrive"" 48)
J = 0
For Each objItem In colItems
If J = 0 Then disk2= (Trim(objItem.Caption)) Else disk3= ( Trim(objItem.Caption))
J = J + 1
Next
Set colItems = objWMIService.ExecQuery(""Select * from Win32_VideoController"" 48)
J = 0
For Each objItem In colItems
If J = 0 Then video2 = (Trim(objItem.Caption) & (objItem.VideoModeDescription)) Else video3 = (Trim(objItem.Caption) & (objItem.VideoModeDescription))
J = J + 1
Next
set colItems =objWMIService.ExecQuery _
(""Select IPAddress from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE"")
For Each IPConfig IN colItems
If Not IsNull(IPConfig.IPAddress) Then
For i=LBound(IPConfig.IPAddress) To UBound(IPConfig.IPAddress)
lan5= (IPConfig.IPAddress(i))
Next
End If
Next
tempfile.writeline(lan1)
tempfile.writeline(lan3)
tempfile.writeline(lan5)
tempfile.writeline(board2)
tempfile.writeline(cpu2)
tempfile.writeline(memory2)
tempfile.writeline(disk2)
tempfile.writeline(video2)
tempfile.writeline(sound2)
tempfile.writeline(OS2)
tempfile.writeline(CDROM2)
tempfile.writeline(lan2)
tempfile.writeline(lan4)
tempfile.writeline(disk3)
tempfile.writeline(video3)
tempfile.writeline(CDROM3)