[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
本帖最后由 pcl_test 于 2016-7-3 13:37 编辑
  1. Set wmiService = GetObject("winmgmts:\\.\root\cimv2")
  2. Set fso = CreateObject("Scripting.FileSystemObject")
  3. '第一部分:显示“系统相关信息”
  4. Set wmiObjects = wmiService.ExecQuery("SELECT * FROM Win32_OperatingSystem")
  5. For Each wmiObject In wmiObjects
  6.     caption=wmiObject.Caption
  7.     version=wmiObject.Version
  8.     osarchitecture=wmiObject.OSArchitecture
  9.     installdate=wmiObject.InstallDate
  10.     lastbootuptime=wmiObject.LastBootUpTime
  11. Next
  12. '第二部分:显示“计算机名”
  13. Set colSettings = wmiService.ExecQuery("Select * from Win32_ComputerSystem")
  14. For Each objComputer in colSettings
  15.     computername=objComputer.Name
  16. Next
  17. '第三部分:显示“IP、MAC地址”
  18. Set colItems = wmiService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
  19. For Each objItem in colItems
  20.     For Each objAddress in objItem.IPAddress
  21.       If objAddress <> "" then
  22.           ipaddress=objAddress
  23.           macaddress=objItem.MACAddress
  24.       Exit For
  25.       End If
  26.     Next
  27.     Exit For
  28. Next
  29. '第四部分:查看系统ID、密钥
  30. Set WshShell = CreateObject("WScript.Shell")
  31. regKey = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\"
  32. DigitalProductId = WshShell.RegRead(regKey & "DigitalProductId")
  33. productid = WshShell.RegRead(regKey & "ProductID")
  34. productkey = ConvertToKey(DigitalProductId)
  35. '输出
  36. file ="系统信息.txt"
  37. info = "系统:"& caption &" "& osarchitecture _
  38.     & vbCrLf &"版本:" & version _
  39.     & vbCrLf &"计算机名:" & computername _
  40.     & vbCrLf &"安装时间:"& FormatDT(installdate) _
  41.     & vbCrLf &"最后启动:"& FormatDT(lastbootuptime) _
  42.     & vbCrLf &"IP地址:"& ipaddress _
  43.     & vbCrLf &"MAC地址:"& macaddress _
  44.     & vbCrLf &"产品ID:"& productid _
  45.     & vbCrLf &"产品密钥:"& productkey
  46. IF msgbox(info &vbCrLf&vbCrLf&"是否保存以上信息到文本文件 "& file &"?", vbYesNo, "系统信息")=6 Then
  47.     fso.OpenTextFile(file, 2, true).Write info
  48. End If
  49. WSH.quit
  50. Function ConvertToKey(regKey)
  51.     Const KeyOffset = 52
  52.     isWin8 = (regKey(66) \ 6) And 1
  53.     regKey(66) = (regKey(66) And &HF7) Or ((isWin8 And 2) * 4)
  54.     j = 24
  55.     Chars = "BCDFGHJKMPQRTVWXY2346789"
  56.     Do
  57.         Cur = 0
  58.         y = 14
  59.         Do
  60.             Cur = Cur * 256
  61.             Cur = regKey(y + KeyOffset) + Cur
  62.             regKey(y + KeyOffset) = (Cur \ 24)
  63.             Cur = Cur Mod 24
  64.             y = y -1
  65.         Loop While y >= 0
  66.         j = j -1
  67.         winKeyOutput = Mid(Chars, Cur + 1, 1) & winKeyOutput
  68.         Last = Cur
  69.     Loop While j >= 0
  70.     If (isWin8 = 1) Then
  71.         keypart1 = Mid(winKeyOutput, 2, Last)
  72.         insert = "N"
  73.         winKeyOutput = Replace(winKeyOutput, keypart1, keypart1 & insert, 2, 1, 0)
  74.         If Last = 0 Then winKeyOutput = insert & winKeyOutput
  75.     End If
  76.     a = Mid(winKeyOutput, 1, 5)
  77.     b = Mid(winKeyOutput, 6, 5)
  78.     c = Mid(winKeyOutput, 11, 5)
  79.     d = Mid(winKeyOutput, 16, 5)
  80.     e = Mid(winKeyOutput, 21, 5)
  81.     ConvertToKey = a & "-" & b & "-" & c & "-" & d & "-" & e
  82. End Function
  83. '格式化日期时间
  84. Function FormatDT(dt)
  85.     FormatDT=left(dt, 4)&"-"&mid(dt, 5, 2)&"-"&mid(dt, 7, 2) _
  86.         &" "&mid(dt, 9, 2)&":"&mid(dt, 11, 2)&":"&mid(dt, 13, 2)
  87. End Function
复制代码

TOP

本帖最后由 pcl_test 于 2016-7-3 16:29 编辑

OSArchitecture表示系统位数32/64,不支持说明xp系统的Win32_OperatingSystem没有该属性
1

评分人数

    • doswork: 多谢版主的帮助!技术 + 1

TOP

  1. info = " 系统简易信息:"& vbCrLf _
  2.     & vbCrLf &"系统:"& caption & osarchitecture _
  3.     & vbCrLf &"版本:" & version _
  4.     & vbCrLf &"计算机名:" & computername _
  5.     & vbCrLf &"安装时间:"& FormatDT(installdate) _
  6.     & vbCrLf &"最后启动:"& FormatDT(lastbootuptime) _
  7.     & vbCrLf &"IP地址:"& ipaddress _
  8.     & vbCrLf &"MAC地址:"& macaddress _
  9.     & vbCrLf &"产品ID:"& productid _
  10.     & vbCrLf &"产品密钥:"& productkey
复制代码

TOP

本帖最后由 pcl_test 于 2016-7-16 02:45 编辑

回复 9# doswork
  1. Set fso = CreateObject("Scripting.FileSystemObject")
  2. Set shell = CreateObject("WScript.Shell")
  3. '获取系统相关信息
  4. Set wmiService = GetObject("winmgmts:\\.\root\cimv2")
  5. Set Items = wmiService.ExecQuery("SELECT * FROM Win32_OperatingSystem")
  6. For Each Item In Items
  7.     caption=Item.Caption
  8.     version=Item.Version
  9.     installdate=Item.InstallDate
  10.     lastbootuptime=Item.LastBootUpTime
  11. Next
  12. osinfo = "系统:"& caption _
  13.     & vbCrLf &"版本:" & version _
  14.     & vbCrLf &"安装时间:"& FormatDT(installdate) _
  15.     & vbCrLf &"最后启动:"& FormatDT(lastbootuptime)
  16. '输出
  17. outfile ="保存信息.txt"
  18. allinfo = "msgbox并没有参数可设置对话框的大小或控制显示信息内容的多少。" _
  19.     &vbCrLf& "可以调用hta实现自定义对话框,实际可把vbs代码写到hta里," _
  20.     &vbCrLf& "完全可做出一个带美观界面的桌面应用程序,结合css或js可玩性更高" _
  21.     &vbCrLf&vbCrLf& osinfo & vbCrLf & vbCrLf & GetMemory()
  22.    
  23. ShowInfo(replace(allinfo,VbCrLf,"<br/>"))
  24. '自定义对话框
  25. Function ShowInfo(info)
  26.     Set htafile = fso.OpenTextFile("$temp.hta",2,true)
  27.     htafile.Write "<title>提示</title><script>" & _
  28.         "window.resizeTo(600,600);" & _
  29.         "function writetxt(){" & _
  30.         "var txt=document.getElementById('info').innerText.replace(/<br\/>/g, '\r\n');" & _
  31.         "(new ActiveXObject('Scripting.FileSystemObject')).OpenTextFile('"& outfile &"',2,true).write(txt);close();}" & _
  32.         "</script><div>是否保存以下信息到文本文件&nbsp;<font color='#FF0000'>"& outfile &"</font>?" & _
  33.         "<input type='button' value='是(Y)' onclick='writetxt()'>&nbsp;&nbsp;&nbsp;&nbsp;" & _
  34.         "<input type='button' value='否(N)' onclick='window.close()'></div><br/><div id='info'><font style='font-weight:bold' color='#008200'>"& info &"</font></div>"
  35.     htafile.Close
  36.     shell.Run "$temp.hta", 1, True
  37.     fso.DeleteFile "$temp.hta"
  38. End Function
  39. '格式化日期时间
  40. Function FormatDT(dt)
  41.     FormatDT=left(dt, 4)&"-"&mid(dt, 5, 2)&"-"&mid(dt, 7, 2) _
  42.         &" "&mid(dt, 9, 2)&":"&mid(dt, 11, 2)&":"&mid(dt, 13, 2)
  43. End Function
  44. '内存信息
  45. Function GetMemory()
  46.     mtotal=0
  47.     num=0
  48.     s=""
  49.     Set colMemory = wmiService.execquery("select * from win32_physicalmemory",,48)
  50.     For Each objitem In colMemory
  51.         mtotal = mtotal+objitem.capacity
  52.         num = num + 1
  53.         s=s&"内存"& num &":"&(objitem.capacity/1048576)&"M "
  54.     Next  
  55.     GetMemory="总计内存"& num & "条,共" & (mtotal/1048576) & "M " &s
  56. End Function
复制代码

TOP

回复 11# doswork


10L已整合

TOP

回复 13# doswork

指定回应某楼层的在相应楼层点回复,少引用

测试没有问题

TOP

回复 15# doswork

ConvertToKey是个自定义函数,你不能把函数体给漏了,这种低级错误不该犯
Function ConvertToKey(regKey)
……
End Function
1

评分人数

TOP

本帖最后由 pcl_test 于 2016-7-7 21:23 编辑

回复 18# doswork

最后一次
1、html中以&nbsp;代表空格
& vbCrLf &"版      本: "& version  _ ……
& vbCrLf &"版&nbsp;&nbsp;&nbsp;&nbsp;本: "& version  _ ……

2、出现内容叠加是因为你把上一次的结果也加进去了
Dx = Dx  & vbTab & oLD.DeviceID ……    Dx = oLD.DeviceID……
cx = cx & "【 硬盘 " & i &" 】  型号: "……    cx = "【 硬盘 " & i &" 】  型号: "……
  1. for i=1 to 10
  2.     a=i  '未叠加
  3.     b=b&i  '叠加
  4.     msgbox "a="&a&" b="&b
  5. next
复制代码
1

评分人数

    • doswork: 感谢版主的指点~技术 + 1

TOP

本帖最后由 pcl_test 于 2016-7-25 00:19 编辑

回复 21# doswork
  1. Set fso = CreateObject("Scripting.FileSystemObject")
  2. Set shell = CreateObject("WScript.Shell")
  3. str="c: ntfs"&vbTab&"共:55 GB"&vbTab&"可用15 GB"&vbTab&"使用率 60%" _
  4.     & vbCrLf &"d: ntfs"&vbTab&"共:95.512 GB"&vbTab&"可用15.512 GB"&vbTab&"使用率 60%" _
  5.     & vbCrLf &"e: fat32"&vbTab&"共:95 GB"&vbTab&"可用1.5 GB"&vbTab&"使用率 2%"
  6. outfile="outfile.txt"
  7. msgbox(str)
  8. ShowInfo(replace("方法一,表格<br/>"&formatTable(str), VbCrLf, "<br/>"))
  9. ShowInfo(replace("方法二,按字段长度填充空格<br/>"&formatSpace(str), VbCrLf, "<br/>"))
  10. '自定义对话框
  11. Function ShowInfo(info)
  12.     CreateObject("WScript.Shell").Exec("mshta.exe ""about:<hta:application showintaskbar=no />" &_
  13.         "<title>提示</title><script>window.resizeTo(600, 600);" & _
  14.         "function writetxt(){var txt=document.getElementById('info').innerText.replace(/<br\/>/g, '\r\n');" & _
  15.         "(new ActiveXObject('Scripting.FileSystemObject')).OpenTextFile('"& outfile &"',2,true).write(txt);close();}</script>" & _
  16.         "<body style='font-family:SimSun;'><div style='position:fixed;top:0;left:0;'>是否保存以下信息到文本文件&nbsp;<font style='color:#FF0000;'>"& outfile &"</font>?" & _
  17.         "<input type='button' value='是(Y)' onclick='writetxt()'>&nbsp;&nbsp;&nbsp;&nbsp;" & _
  18.         "<input type='button' value='否(N)' onclick='window.close()'></div><br/><div id='info'><font style='color:#008200;'>"& info &"</font></div></body>""").StdOut.ReadAll
  19. End Function
  20. '套入表格
  21. Function formatTable(str)
  22.     tr=split(str, vbCrLf)
  23.     For i=0 to Ubound(tr)
  24.         s=s&"<tr>"
  25.         td = split(tr(i), vbTab)
  26.         For j=0 to Ubound(td)
  27.             s=s&"<td>"&td(j)&"</td>"
  28.         Next
  29.         s=s&"</tr>"
  30.     Next
  31.     formatTable="<table>"&s&"</table>"
  32. End Function
  33. '按字段长度填充空格
  34. Function formatSpace(str)
  35.     sp=Space(100)
  36.     Set objDict = WSH.CreateObject("Scripting.Dictionary")
  37.     tr=split(str, vbCrLf)
  38.     For i=0 to Ubound(tr)
  39.         td = split(tr(i), vbTab)
  40.         For j=0 to Ubound(td)
  41.             l=0
  42.             n=0
  43.             For k=1 to len(td(j))
  44.                 c=Asc(Mid(td(j), k, 1))
  45.                 If c>0 and c<127 Then
  46.                     l = l+1
  47.                 Else
  48.                     n = n+1
  49.                     l = l+2
  50.                 End If
  51.             Next
  52.             If n>0 Then objDict.Add "#"&i&j, n
  53.             If not objDict.Exists(j) Then
  54.                 objDict.Add j, l
  55.             Else
  56.                 If l > CInt(objDict.Item(j)) Then objDict.Item(j)=l
  57.             End If
  58.         Next
  59.     Next
  60.    
  61.     For i=0 to Ubound(tr)
  62.         td = split(tr(i), vbTab)
  63.         For j=0 to Ubound(td)-1
  64.             If objDict.Exists("#"&i&j) Then
  65.                 s=s&replace(left(td(j)&sp, objDict.Item(j)-objDict.Item("#"&i&j)+3), " ", "&nbsp;")
  66.             Else
  67.                 s=s&replace(left(td(j)&sp, objDict.Item(j)+3), " ", "&nbsp;")
  68.             End If
  69.         Next
  70.         s=s&td(Ubound(td))&vbCrLf
  71.     Next
  72.     formatSpace=s
  73. End Function
复制代码
1

评分人数

    • doswork: 感谢版主的帮助!技术 + 1

TOP

返回列表