VbScript獲取本地機器的硬體配置

dingonet發表於2008-09-01
網上看到有人做了一個檔案,居然要付錢下載,很生氣。自己動手寫了一個,沒有將配置寫入到檔案。只是回顯到控制檯。當然可以很容易就回顯到本地檔案了。cscript xxx.vbs>>d:config.txt就可以了。呵呵簡單吧![@more@]

'On Error Resume Next
Dim fso,f1

strComputer = "."

If Err.Description = "" Then

'收集計算機使用者資訊
Set objWmi = GetObject("winmgmts:" & strComputer & "rootcimv2")

'收集本地計算機名稱,若收集計算機登入帳戶的話則使用objItem.UserName
Set colItems = objWmi.ExecQuery("Select * from Win32_ComputerSystem", , 48)
J = 0
For Each objItem In colItems
'If J = 0 Then f1.write (Trim(objItem.Name)) Else f1.write ("," & Trim(objItem.Name))
'J = J + 1
computerName= Trim(objItem.name)
Next

''create filename as computername
'Set fso = CreateObject("Scripting.FileSystemObject")
'Set f1 = fso.CreateTextFile("c:" & computerName & ".txt")
'收集CPU資訊

'Set objWmi = GetObject("winmgmts:" & strComputer & "rootcimv2")
Set colItems = objWmi.ExecQuery("Select * from Win32_Processor", , 48)
J = 1
For Each objItem In colItems
'If J = 0 Then f1.write (Trim(objItem.Name)) Else f1.write ("," & Trim(objItem.Name))
'J = J + 1
wscript.echo "Cpu type:" & Trim(objItem.Name)
Next

'收集記憶體資訊
'收集記憶體總容量
'Set objWmi = GetObject("winmgmts:" & strComputer & "rootcimv2")
Set colItems = objWmi.ExecQuery("Select * from Win32_ComputerSystem", , 48)
J = 2
For Each objItem In colItems
'If J = 0 Then f1.write (Trim(objItem.TotalPhysicalMemory)) Else f1.write ("," & Trim(objItem.TotalPhysicalMemory))
'J = J + 1
wscript.echo "physical Memery:" & Round(Round(objItem.TotalPhysicalMemory/1024)) & " Mb"
Next

'收集記憶體外頻和數量資訊
'Set objWmi = GetObject("winmgmts:" & strComputer & "rootcimv2")
'Set colItems = objWmi.ExecQuery("Select * from Win32_PhysicalMemory", , 48)
'J = 3
'For Each objItem In colItems
'If J = 0 Then f1.write (Trim(objItem.Description) & (objItem.DeviceLocator) & (objItem.Speed)) Else f1.write ("," & Trim(objItem.Description) & (objItem.DeviceLocator) & "," & Trim(objItem.Speed))
'J = J + 1
'wscript.echo "Cpu type:" & objItem.Name
'Next

'收集顯示卡資訊
'Set objWmi = GetObject("winmgmts:" & strComputer & "rootcimv2")
Set colItems = objWmi.ExecQuery("Select * from Win32_VideoController", , 48)
J = 4
For Each objItem In colItems
'If J = 0 Then f1.write (Trim(objItem.Caption) & (objItem.VideoModeDescription)) Else f1.write ("," & Trim(objItem.Caption) & (objItem.VideoModeDescription))
'J = J + 1
wscript.echo "VideoController:" & objItem.Caption
Next

'收集硬碟基本資訊
'Set objWmi = GetObject("winmgmts:" & strComputer & "rootcimv2")
Set colItems = objWmi.ExecQuery("Select * from Win32_DiskDrive", , 48)
J = 5
For Each objItem In colItems
'If J = 0 Then f1.write (Trim(objItem.Caption) & (objItem.Size)) Else f1.write ("," & Trim(objItem.Caption) & "," & (objItem.Size))
'J = J + 1
wscript.echo "HardDisk :" & objItem.Caption &" HardDisk Size: " & Round(Round(Round(objItem.Size/1000)/1000)/1000) & " G"
Next

'收集音效卡資訊
'Set objWmi = GetObject("winmgmts:" & strComputer & "rootcimv2")
Set colItems = objWmi.ExecQuery("Select * from Win32_SoundDevice", , 48)
J = 6
For Each objItem In colItems
'If J = 0 Then f1.write (Trim(objItem.ProductName)) Else f1.write ("," & Trim(objItem.ProductName))
'J = J + 1
wscript.echo "SoundCard:" & objItem.productName
Next

'收集網路卡資訊
'Set objWmi = GetObject("winmgmts:" & strComputer & "rootcimv2")
Set colItems = objWmi.ExecQuery("Select * from Win32_NetworkAdapter ", , 48)
For Each objItem In colItems
'If J = 0 Then f1.write (Trim(objItem.Description) & (objItem.MACAddress)) Else f1.write ("," & Trim(objItem.ProductName) & "," & (objItem.MACAddress))
'J = J + 1
wscript.echo "NetWorkCard:" & Trim(objItem.Description) & " Mac Address:" & Trim(objItem.MAcaddress)
Next


'收集軟碟機資訊
'Set objWmi = GetObject("winmgmts:" & strComputer & "rootcimv2")
Set colItems = objWmi.ExecQuery("Select * from Win32_FloppyDrive", , 48)
J = 8
For Each objItem In colItems
'If J = 0 Then f1.write (Trim(objItem.Caption)) Else f1.write ("," & Trim(objItem.Caption))
'J = J + 1
wscript.echo "Floppy Driver:" & Trim(objItem.Caption)
Next

'收集CDROM資訊
'Set objWmi = GetObject("winmgmts:" & strComputer & "rootcimv2")
Set colItems = objWmi.ExecQuery("Select * from Win32_CDROMDrive", , 48)
J = 9
For Each objItem In colItems
'If J = 0 Then f1.write (Trim(objItem.Name)) Else f1.write ("," & Trim(objItem.Name))
'J = J + 1
wscript.echo "Dvd Driver:" & Trim(objItem.Name)
Next


End If
'f1.WriteLine ("")
'f1.Close
'Set f1=Nothing

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/77544/viewspace-1009913/,如需轉載,請註明出處,否則將追究法律責任。

相關文章