Èí¼þ¿ª·¢Åàѵ°à >> ±à³Ì¿ª·¢ >> VbScript
vbs查询局域网内电脑的软件和硬件列表清� target= |
|
¡¡¡¡±¾ÎıêÇ©£ºè½¯ä»¶åˆ—表,硬件列表 下é�¢çš„代ç �在windows下容易报毒大家å�¯ä»¥æ”¾å¿ƒä½¿ç”?/p>
'==========================================================================
'
' Date:2009/3/19
' Name: 查询软件和硬件列表清�
' Author:Smileruner
' www.overmcse.com
' �支�Win2000�WinNT
'
' 3/19,æ·»åŠ äº†ç½‘å�¡è¿‡æ»¤ã€?
'==========================================================================
'on error resume Next
const HKEY_LOCAL_MACHINE = &H80000002
const UNINSTALL_ROOT = "SoftwareMicrosoftWindowsCurrentVersionUninstall"
const REG_SZ = 1
'Set wshshell=wscript.createobject("wscript.shell")
' wshshell.run ("%comspec% /c regsvr32 /s scrrun.dll"),0,true
' wshshell.run ("%comspec% /c sc config winmgmt start= auto"),0,true
' wshshell.run ("%comspec% /c net start winmgmt"),0
strComputer = Inputbox("请输入�查询的计算机�称",,"")
If strComputer = "" then
Wscript.Echo "未输入值或用户�消,查询退出�
Wscript.Quit
End If
Set objswbemlocator = createobject("wbemscripting.swbemlocator")
Set objswbemservices = objswbemlocator.connectserver(strComputer, "rootcimv2")
If Err.number <> 0 then
Wscript.Echo "ç›®æ ‡è®¡ç®—æœºæ— æ³•è¿žæŽ¥ã€‚é”™è¯¯çš„è®¡ç®—æœºå��ï¼Œæˆ–ç›®æ ‡è®¡ç®—æœºå�¯ç”¨äº†é˜²ç�«å¢™ï¼ŒRPCæœ�务ä¸�å�¯ç”¨ã€?
Err.number.clear
Wscript.Quit
End If
'swbemservices.security_.impersonationleobjvel = 3
Set fso=createobject("scripting.filesystemobject")
FileDate = Replace(date(), "/", "-")
resoultfilepath= strComputer & FileDate & ".html"
Set resultFile= fso.createtextfile(resoultfilepath,,true)
HtmlWriteHead()
'Htmlæ–‡æ ¡£å¼€å§?
TableHead strComputer,"硬件清�"
'Htmlè¡¨æ ¼å¼€å§?
OsWrite()
'写入�作系统信�
BoardWrite()
'写入主�信�
CpuWrite()
'写入CPU信�
MemoryWrite()
'写入内å˜ä¿¡æ�¯
HarddiskWrite()
'写入硬盘信�
CdromWrite()
'写入CDROM信�
VideoWrite()
'写入显示�信�
NetcardWrite()
'写入网�信�
TableEnd()
'Htmlè¡¨æ ¼ç»“å°¾
TableHead strComputer,"软件清�"
'Htmlè¡¨æ ¼å¼€å¤?
Softlist()
'写入软件信�
TableEnd()
'Htmlè¡¨æ ¼ç»“å°¾
HtmlWriteEnd()
'Htmlæ–‡æ ¡£ç»“æ�Ÿ
ResultFile.close
Wscript.Echo "查询完��
'=========以下是函数列�=========
Function OsWrite()
'函数,写入�作系统信�
Set colOs =objswbemservices.execquery("select * from win32_operatingsystem",,48)
For Each Ositem In colOs
oscaption = Ositem.caption
OsVersion = oscaption & Ositem.version
WriteTable "�作系统",OsVersion
Next
End Function
Function BoardWrite()
'函数,写入主�信�
Set colBoard = objswbemservices.execquery("select * from win32_baseboard")
For Each Bditem In colBoard
boardname = Bditem.product
WriteTable "主�",boardname
Next
End Function
Function CpuWrite()
'函数,写入CPU信�
Set colCpu =objswbemservices.execquery("select * from win32_processor")
For Each item in colCpu
cpuname = (trim(item.name))
WriteTable "ä¸å¤®å¤„ç�†å™?,cpuname
Next
End Function
Function MemoryWrite()
'函数,写入内å˜ä¿¡æ�?
mtotal = 0
num = 0
mill = 0
Set colMemory = objswbemservices.execquery("select * from win32_physicalmemory",,48)
For Each objitem In colMemory
mill = objitem.capacity/1048576
WriteTable "å�•æ ¹å†…å˜å®¹é‡�",mill & "M"
mtotal = mtotal+mill
num = num + 1
Next
WriteTable "总计内å˜",num & "æ�? & "一å…? & mtotal & "M"
End Function
Function HarddiskWrite()
'函数,写入硬盘信�
Set colDisk = objswbemservices.execquery("select * from win32_diskdrive", , 48)
For Each objitem In colDisk
diskname= objitem.caption
disksize= fix(objitem.size/1073741824)
WriteTable "硬盘",diskname & " 容�� & disksize & "G"
Next
End Function
Function CdromWrite()
'函数,写入CDROM信�
Set colCdrom = objswbemservices.execquery("select * from win32_cdromdrive where scsitargetid=0")
For Each objitem In colCdrom
cdname = objitem.name
WriteTable "光驱",cdname
Next
End Function
Function videoWrite()
'函数,写入显示�信�
Set colVideo = objswbemservices.execquery("select * from win32_videocontroller", , 48)
For Each objitem in colVideo
videoname = (trim(objitem.caption) & (objitem.videomodedescription))
WriteTable "显示�,videoname
Next
End Function
Function netcardWrite()
'函数,查询网�信�
Set colNetcards = objswbemservices.execquery("select * from win32_networkadapter")
For Each objNetcard in colNetcards
If Not IsNull(objNetcard.NetConnectionID) Then
NetCardName = objNetcard.productname
WriteTable "网��称",NetCardName
If objNetcard.NetConnectionStatus = 2 Then
NetCardMac = objNetcard.macaddress
WriteTable "网�Mac",NetCardMac
strQueryIp ="select * from win32_networkadapterconfiguration" &_
" where IPEnabled = true" &_
" and macaddress = '" & objNetcard.macaddress & "'"
Set colNetcardCfgs = objswbemservices.execquery(strQueryIp)
For Each objNetcardCfg in colNetcardCfgs
For Each CfgAdrress in objNetcardCfg.IPAddress
IpAdrress = CfgAdrress
WriteTable "IP地�",IpAdrress
Next
Next
Else
NetCardMac = "网�被�用或未连接�
WriteTable "网�Mac",NetCardMac
IpAdrress = "网�被�用或未连接�
WriteTable "IP地�",IpAdrress
End If
End if
Next
End Function
Function softlist()
'函数,写入软件信�
Set StdOut = WScript.StdOut
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\" &_
strComputer & "
ootdefault:StdRegProv")
strKeyPath = UNINSTALL_ROOT
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each strSubKey In arrSubKeys
If NotHotfix(strSubKey) Then
SoftNameAndVersion = getProgNameAndVersion(oReg,strKeyPath & "" & strSubKey)
If SoftNameAndVersion<>"0" Then
WriteTable "软件",SoftNameAndVersion
End If
End If
Next
End Function
Function NotHotfix(sSubKey)
If Left(sSubkey,2) = "KB" And len(sSubkey) = 8 Then
NotHotfix = 0
Else NotHotfix = 1
End if
End Function
Function getProgNameAndVersion(oReg,sKeyRoot)
Dim sKeyValuesAry, iKeyTypesAry, nCnt, sValue, sDisplayName, sDisplayVersion
oReg.EnumValues HKEY_LOCAL_MACHINE, sKeyRoot, sKeyValuesAry, iKeyTypesAry
If NOT IsArray(sKeyValuesAry) Then
getProgNameAndVersion = 0
Exit Function
End If
For nCnt = 0 To UBound(sKeyValuesAry)
If InStr(1, sKeyValuesAry(nCnt), "DisplayName", vbTextCompare) Then
If iKeyTypesAry(nCnt) = REG_SZ Then
oReg.GetStringValue HKEY_LOCAL_MACHINE, sKeyRoot, sKeyValuesAry(nCnt), sValue
If sValue<>"" Then
sDisplayName = sValue
sDisplayName = Replace(sDisplayName, "[", "(")
sDisplayName = Replace(sDisplayName, "]", ")")
End If
End If
ElseIf InStr(1, sKeyValuesAry(nCnt), "DisplayVersion", vbTextCompare) Then
If iKeyTypesAry(nCnt) = REG_SZ Then
oReg.GetStringValue HKEY_LOCAL_MACHINE, sKeyRoot, sKeyValuesAry(nCnt), sValue
If sValue<>"" Then sDisplayVersion = sValue
End If
End If
If (sDisplayName<>"") AND (sDisplayVersion<>"") Then
getProgNameAndVersion = sDisplayName & " --版本� " & sDisplayVersion
Exit Function
Else getProgNameAndVersion = 0
End If
Next
If sDisplayName<>"" Then
getProgNameAndVersion = sDisplayName
Exit Function
End If
End Function
Function WriteTable(caption,value)
'函数,将数æ�®å†™å…¥HTMLå�•å…ƒæ ?
resultFile.Writeline "<tr>"
resultFile.Writeline "<td align=""left"" width=""30%"" height=""25"" bgcolor=""#ffffff"" scope=""row""> " & caption & "</td>"
resultFile.Writeline "<td bgcolor=""#ffffff""> " & value & "</td>"
resultFile.Writeline "</tr>"
End Function
Function HtmlWriteHead()
'函数,写入THML文件�
resultFile.Writeline "<html>"
resultFile.Writeline "<head>"
resultFile.Writeline "<title>软硬件�置清�lt;/title>"
resultFile.Writeline "</head>"
resultFile.Writeline "<body>"
End Function
Function HtmlWriteEnd()
'函数,写入Html文件�
resultFile.Writeline "</body>"
resultFile.Writeline "</html>"
End Function
Function TableHead(pcname,str)
'函数,写入Htmlè¡¨æ ¼ç»“å°¾
resultFile.Writeline "<h3>" & pcname & str & " -- date:"&now()&" </h3>" & VbCrLf
resultFile.Writeline "<table width=""90%"" border=""0"" align=""center"" cellpadding=""0"" cellspacing=""1"" bgcolor=""#0000ff"">"
resultFile.Writeline "<tr>"
resultFile.Writeline "<th width=""30%"" height=""25"" bgcolor=""#ffffff"" scope=""col"">资产类型</th>"
resultFile.Writeline "<th bgcolor=""#ffffff"" scope=""col"">查询结果�lt;/th>"
resultFile.Writeline "</tr>"
strstyle = "<th width=""30%"" height=""25"" bgcolor=""#ffffff"" scope=""row"">"
End Function
Function TableEnd()
'函数,Htmlè¡¨æ ¼ç»“å°¾
resultFile.Writeline "</table>"
End Function
vbsåˆ¤æ–æ“�作系统
strComputer = "."
Set objWMIService = GetObject("winmgmts:\" & strComputer & "
ootcimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objItem in colItems
strOSVersion = objItem.Version
Next
wscript.echo strOSversion
select case strOSversion
case "5.2.3790"
wscript.echo "Windows Server 2003"
case "5.0.2195"
wscript.echo "Windows 2000"
case "5.1.2600"
wscript.echo "Windows XP"
case "6.0.6001"
wscript.echo "windows visita"
Case "6.1.7601"
wscript.echo "Windows Server 2008 r2"
case else
wscript.echo "i don't know"
end select
到æ¤è¿™ç¯‡å…³äºŽvbs查询局域网内电脑的软件和硬件列表清å�•çš„æ–‡ç« å°±ä»‹ç»�到这了,更多相关查询软件和硬件列表清å�•内容请æ�œç´¢è„šæœ¬ä¹‹å®¶ä»¥å‰�çš„æ–‡ç« æˆ–ç»§ç»æµ�览下é�¢çš„ç›¸å…³æ–‡ç« å¸Œæœ›å¤§å®¶ä»¥å�Žå¤šå¤šæ”¯æŒ�脚本之家ï¼� |