标题: [系统相关] 想整合个VBS和bat,并稍作改进,望指教 [打印本页]
作者: vszy 时间: 2020-6-26 21:05 标题: 想整合个VBS和bat,并稍作改进,望指教
VBS脚本如下:- On Error Resume Next
- Dim WMI,WS,Fso
- Set WMI = GetObject("Winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
- Set cOSs = WMI.ExecQuery("Select * from Win32_OperatingSystem")
- For Each oOS in cOSs
- OSx = oOS.Caption &" " & oOS.CSDVersion & vbCrLf
- Next
- CPUx = "———————————处理器信息———————————" & vbCrLf
- Set CPUs = WMI.InstancesOf("Win32_Processor")
- Set Caches = WMI.InstancesOf("Win32_CacheMemory")
- For Each ObjCPU In CPUs
- MCS = ObjCPU.MaxClockSpeed :CCS = ObjCPU.CurrentClockSpeed
- If ObjCPU.MaxClockSpeed Mod 2 = 1 Then MCS = CCS + 1
- If ObjCPU.CurrentClockSpeed Mod 2 = 1 Then CCS = CCS + 1
- OC = QOC(CCS,MCS)
- If (OC-MCS) > 10 and (OC-MCS) > 0 Then OCLC = " 超频比率: " & FormatPercent((OC-MCS)/MCS)
- If (OC-MCS) < -10 and (OC-MCS) < 0 Then OCLC = " 降频比率: " & FormatPercent((OC-MCS)/MCS)
- CPUx = CPUx _
- & "CPU 名称: " & Trim(ObjCPU.Name) & vbCrLf
- Next
- Set Caches = Nothing:Set CPUs = Nothing
-
- Memx = "————————————内存信息————————————" & vbCrLf
- Set Memorys = WMI.InstancesOf("Win32_PhysicalMemory")
- Set MemKY = WMI.InstancesOf("Win32_OperatingSystem")
- For Each aKY In MemKY
- ZL = aKY.TotalVisibleMemorySize
- KY = aKY.FreePhysicalMemory
- Next
- Mems = 0:Memc = 0
- Types = Array("Unknown","Other","DRAM","Synchronous DRAM","Cache DRAM","EDO","EDRAM","VRAM","SRAM", "RAM", _
- "ROM","Flash","EEPROM","FEPROM","EPROM","CDRAM","3DRAM","SDRAM","SGRAM","RDRAM","DDR","DDR2")
- For Each Mem In Memorys
- For i = 0 To UBound(Types)
- If Mem.MemoryType = i Then MemType = Types(i) :End If
- Next
- For j = 0 To 6
- Select Case Mem.Tag
- case "Physical Memory " & j
- Mems = Mems+(Mem.Capacity)
- Memx = Memx &"插槽" & Mem.DeviceLocator & ": " & Round(Mem.Capacity/1048576) &" MB " _
- & MemType & "-" & Mem.Speed & "MHz" & " 数据带宽" & Mem.DataWidth _
- & "Bit" & " 总带宽" & Mem.TotalWidth &"Bit" & vbCrLf
- End Select
- Next
- Next
- Memx = Memx _
- & "内存安装: "& Round(Mems/1048576)&" MB " & vbCrLf
- Set Memorys = Nothing:Set MemKY = Nothing
-
- Set cNet = Nothing
-
- If (Lcase(Right(Wscript.FullName,11)) = "wscript.exe") Then
- JZCSx = JZCS :wInfo
- Else
- WScript.Echo CPUx & Memx
- End If
- Set WMI = Nothing
-
- Sub wInfo()
- Set WS = CreateObject("WScript.Shell")
- Set Fso = CreateObject("Scripting.FileSystemObject")
- aFile = WS.CurrentDirectory &"\"& WS.ExpandEnvironmentStrings("%COMPUTERNAME%")&"_Info.txt"
- Set HInfo = Fso.CreateTextFile(aFile , True)
- HInfo.WriteLine CPUx & Memx
- HInfo.Close
- Set WS = Nothing:Set Fso = Nothing:Set HInfo = Nothing
- End Sub
复制代码
会在VBS当前目录生产个TXT,效果如图:
Bat内容:- :On Error Resume Next
- Sub bat
- echo '>nul&ipconfig /all > Network.txt
- end sub
- echo '>nul&start wscript -e:vbs "%~f0"&&exit
- Wscript.Echo QueryWinVer() & vbCrLf & QueryDirectX() & vbCrLf & _
- QueryIEVer() & vbCrLf & QueryFlashVer() & vbCrLf & _
- QueryMediaVer() & vbCrLf & QueryVC20xx() & vbCrLf & _
- QueryXML() & vbCrLf & QueryNET()
- Function QueryWinVer()
- '查询WMI的Win32_OperatingSystem和Win32_ComputerSystem,读取操作系统版本
- Dim objSWbemServices, objSWbemObject
- Set objSWbemServices = GetObject("Winmgmts:\\.\Root\Cimv2")
- For Each objSWbemObject In objSWbemServices.InstancesOf("Win32_OperatingSystem")
- QueryWinVer = objSWbemObject.Caption & " " & objSWbemObject.CSDVersion
- Next
- QueryWinVer = QueryWinVer & vbCrLf
- For Each objSWbemObject In objSWbemServices.InstancesOf("Win32_ComputerSystem")
- If InStr(objSWbemObject.SystemType, "86") > 0 Then
- QueryWinVer = QueryWinVer & "32位 操作系统"
- ElseIf InStr(objSWbemObject.SystemType, "64") > 0 Then
- QueryWinVer = QueryWinVer & "64位 操作系统"
- Else
- QueryWinVer = QueryWinVer & objSWbemObject.SystemType
- End If
- Next
- QueryWinVer = QueryWinVer & vbCrLf
- End Function
复制代码
也会生成个TXT,如图:
想合并成一个VBS,运行时先有个提示框,输入得到TXT的文件名,TXT内如如下:
多谢各位朋友了
作者: WHY 时间: 2020-6-27 13:33
第二个 bat 只是输出了 ipconfig /all 而已
直接在 HInfo.Close 的下一行插入一行内容,即可完成所谓的“代码合并”:- ws.Run "CMD /C ipconfig /all >> " & chr(34) & aFile & chr(34), 0, true
复制代码
作者: vszy 时间: 2020-6-27 22:35
回复 2# WHY
果然强大,多谢
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |