本帖最后由 pcl_test 于 2016-7-3 13:37 编辑
- Set wmiService = GetObject("winmgmts:\\.\root\cimv2")
- Set fso = CreateObject("Scripting.FileSystemObject")
-
- '第一部分:显示“系统相关信息”
- Set wmiObjects = wmiService.ExecQuery("SELECT * FROM Win32_OperatingSystem")
- For Each wmiObject In wmiObjects
- caption=wmiObject.Caption
- version=wmiObject.Version
- osarchitecture=wmiObject.OSArchitecture
- installdate=wmiObject.InstallDate
- lastbootuptime=wmiObject.LastBootUpTime
- Next
-
- '第二部分:显示“计算机名”
- Set colSettings = wmiService.ExecQuery("Select * from Win32_ComputerSystem")
- For Each objComputer in colSettings
- computername=objComputer.Name
- Next
-
- '第三部分:显示“IP、MAC地址”
- Set colItems = wmiService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
- For Each objItem in colItems
- For Each objAddress in objItem.IPAddress
- If objAddress <> "" then
- ipaddress=objAddress
- macaddress=objItem.MACAddress
- Exit For
- End If
- Next
- Exit For
- Next
-
- '第四部分:查看系统ID、密钥
- Set WshShell = CreateObject("WScript.Shell")
- regKey = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\"
- DigitalProductId = WshShell.RegRead(regKey & "DigitalProductId")
-
- productid = WshShell.RegRead(regKey & "ProductID")
- productkey = ConvertToKey(DigitalProductId)
-
- '输出
- file ="系统信息.txt"
- info = "系统:"& caption &" "& osarchitecture _
- & vbCrLf &"版本:" & version _
- & vbCrLf &"计算机名:" & computername _
- & vbCrLf &"安装时间:"& FormatDT(installdate) _
- & vbCrLf &"最后启动:"& FormatDT(lastbootuptime) _
- & vbCrLf &"IP地址:"& ipaddress _
- & vbCrLf &"MAC地址:"& macaddress _
- & vbCrLf &"产品ID:"& productid _
- & vbCrLf &"产品密钥:"& productkey
-
- IF msgbox(info &vbCrLf&vbCrLf&"是否保存以上信息到文本文件 "& file &"?", vbYesNo, "系统信息")=6 Then
- fso.OpenTextFile(file, 2, true).Write info
- End If
- WSH.quit
-
- Function ConvertToKey(regKey)
- Const KeyOffset = 52
- isWin8 = (regKey(66) \ 6) And 1
- regKey(66) = (regKey(66) And &HF7) Or ((isWin8 And 2) * 4)
- j = 24
- Chars = "BCDFGHJKMPQRTVWXY2346789"
- Do
- Cur = 0
- y = 14
- Do
- Cur = Cur * 256
- Cur = regKey(y + KeyOffset) + Cur
- regKey(y + KeyOffset) = (Cur \ 24)
- Cur = Cur Mod 24
- y = y -1
- Loop While y >= 0
- j = j -1
- winKeyOutput = Mid(Chars, Cur + 1, 1) & winKeyOutput
- Last = Cur
- Loop While j >= 0
- If (isWin8 = 1) Then
- keypart1 = Mid(winKeyOutput, 2, Last)
- insert = "N"
- winKeyOutput = Replace(winKeyOutput, keypart1, keypart1 & insert, 2, 1, 0)
- If Last = 0 Then winKeyOutput = insert & winKeyOutput
- End If
- a = Mid(winKeyOutput, 1, 5)
- b = Mid(winKeyOutput, 6, 5)
- c = Mid(winKeyOutput, 11, 5)
- d = Mid(winKeyOutput, 16, 5)
- e = Mid(winKeyOutput, 21, 5)
- ConvertToKey = a & "-" & b & "-" & c & "-" & d & "-" & e
- End Function
-
- '格式化日期时间
- Function FormatDT(dt)
- FormatDT=left(dt, 4)&"-"&mid(dt, 5, 2)&"-"&mid(dt, 7, 2) _
- &" "&mid(dt, 9, 2)&":"&mid(dt, 11, 2)&":"&mid(dt, 13, 2)
- End Function
复制代码
|