[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[系统相关] 想整合个VBS和bat,并稍作改进,望指教

VBS脚本如下:
  1. On Error Resume Next
  2. Dim WMI,WS,Fso
  3. Set WMI = GetObject("Winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
  4. Set cOSs = WMI.ExecQuery("Select * from Win32_OperatingSystem")
  5. For Each oOS in cOSs
  6. OSx = oOS.Caption &" " & oOS.CSDVersion  & vbCrLf
  7. Next
  8. CPUx = "———————————处理器信息———————————"  & vbCrLf
  9. Set CPUs = WMI.InstancesOf("Win32_Processor")
  10. Set Caches = WMI.InstancesOf("Win32_CacheMemory")
  11. For Each ObjCPU In CPUs
  12. MCS = ObjCPU.MaxClockSpeed :CCS = ObjCPU.CurrentClockSpeed
  13. If ObjCPU.MaxClockSpeed Mod 2 = 1 Then MCS = CCS + 1
  14. If ObjCPU.CurrentClockSpeed Mod 2 = 1 Then CCS = CCS + 1
  15. OC = QOC(CCS,MCS)
  16. If (OC-MCS) >  10 and (OC-MCS) > 0 Then OCLC = "  超频比率: " & FormatPercent((OC-MCS)/MCS)
  17. If (OC-MCS) < -10 and (OC-MCS) < 0 Then OCLC = "  降频比率: " & FormatPercent((OC-MCS)/MCS)
  18. CPUx = CPUx _
  19.      & "CPU 名称: " & Trim(ObjCPU.Name)                & vbCrLf
  20. Next
  21. Set Caches = Nothing:Set CPUs = Nothing
  22. Memx = "————————————内存信息————————————" & vbCrLf
  23. Set Memorys = WMI.InstancesOf("Win32_PhysicalMemory")
  24. Set MemKY = WMI.InstancesOf("Win32_OperatingSystem")
  25. For Each aKY In MemKY
  26.     ZL = aKY.TotalVisibleMemorySize
  27.     KY = aKY.FreePhysicalMemory
  28. Next
  29. Mems = 0:Memc = 0
  30. Types = Array("Unknown","Other","DRAM","Synchronous DRAM","Cache DRAM","EDO","EDRAM","VRAM","SRAM", "RAM", _
  31.                "ROM","Flash","EEPROM","FEPROM","EPROM","CDRAM","3DRAM","SDRAM","SGRAM","RDRAM","DDR","DDR2")
  32. For Each Mem In Memorys
  33.     For i = 0 To UBound(Types)
  34.         If Mem.MemoryType = i Then MemType = Types(i) :End If
  35.     Next
  36.     For j = 0 To 6
  37.         Select Case Mem.Tag
  38.             case "Physical Memory " & j
  39.             Mems = Mems+(Mem.Capacity)
  40.             Memx = Memx  &"插槽" & Mem.DeviceLocator & ": " & Round(Mem.Capacity/1048576) &" MB  " _
  41.                          & MemType & "-" & Mem.Speed & "MHz" & " 数据带宽" & Mem.DataWidth _
  42.                          & "Bit" & " 总带宽" & Mem.TotalWidth &"Bit" & vbCrLf
  43.         End Select
  44.     Next
  45. Next
  46. Memx = Memx _
  47.      & "内存安装: "& Round(Mems/1048576)&" MB " & vbCrLf
  48. Set Memorys = Nothing:Set MemKY = Nothing
  49. Set cNet = Nothing
  50. If (Lcase(Right(Wscript.FullName,11)) = "wscript.exe") Then
  51.     JZCSx = JZCS :wInfo
  52.     Else
  53.     WScript.Echo CPUx & Memx
  54. End If
  55. Set WMI = Nothing
  56. Sub wInfo()
  57.     Set WS = CreateObject("WScript.Shell")
  58.     Set Fso = CreateObject("Scripting.FileSystemObject")
  59.     aFile = WS.CurrentDirectory &"\"& WS.ExpandEnvironmentStrings("%COMPUTERNAME%")&"_Info.txt"
  60.     Set HInfo = Fso.CreateTextFile(aFile , True)
  61.     HInfo.WriteLine CPUx & Memx
  62.     HInfo.Close
  63. Set WS = Nothing:Set Fso = Nothing:Set HInfo = Nothing
  64. End Sub
复制代码
会在VBS当前目录生产个TXT,效果如图:

Bat内容:
  1. :On Error Resume Next
  2. Sub bat
  3. echo '>nul&ipconfig /all > Network.txt
  4. end sub
  5. echo '>nul&start wscript -e:vbs "%~f0"&&exit
  6. Wscript.Echo QueryWinVer()   & vbCrLf & QueryDirectX()  & vbCrLf & _
  7.              QueryIEVer()    & vbCrLf & QueryFlashVer() & vbCrLf & _
  8.              QueryMediaVer() & vbCrLf & QueryVC20xx()   & vbCrLf & _
  9.              QueryXML()      & vbCrLf & QueryNET()
  10. Function QueryWinVer()
  11.     '查询WMI的Win32_OperatingSystem和Win32_ComputerSystem,读取操作系统版本
  12.     Dim objSWbemServices, objSWbemObject
  13.     Set objSWbemServices = GetObject("Winmgmts:\\.\Root\Cimv2")
  14.     For Each objSWbemObject In objSWbemServices.InstancesOf("Win32_OperatingSystem")
  15.         QueryWinVer = objSWbemObject.Caption & " " & objSWbemObject.CSDVersion
  16.     Next
  17.     QueryWinVer = QueryWinVer & vbCrLf
  18.     For Each objSWbemObject In objSWbemServices.InstancesOf("Win32_ComputerSystem")
  19.         If InStr(objSWbemObject.SystemType, "86") > 0 Then
  20.             QueryWinVer = QueryWinVer & "32位 操作系统"
  21.         ElseIf InStr(objSWbemObject.SystemType, "64") > 0 Then
  22.             QueryWinVer = QueryWinVer & "64位 操作系统"
  23.         Else
  24.             QueryWinVer = QueryWinVer & objSWbemObject.SystemType
  25.         End If
  26.     Next
  27.     QueryWinVer = QueryWinVer & vbCrLf
  28. End Function
复制代码
也会生成个TXT,如图:

想合并成一个VBS,运行时先有个提示框,输入得到TXT的文件名,TXT内如如下:

多谢各位朋友了

第二个 bat 只是输出了 ipconfig  /all 而已

直接在 HInfo.Close 的下一行插入一行内容,即可完成所谓的“代码合并”:
  1. ws.Run "CMD /C ipconfig /all >> " & chr(34) & aFile & chr(34), 0, true
复制代码

TOP

回复 2# WHY


果然强大,多谢

TOP

返回列表