Windows get CPU, memory, and disk usage scripts

Time:2022-5-5

Reprinted from: https://blog.51cto.com/luweikai/1904427

reference resources: http://www.51testing.com/html/85/87885-17546.html

   https://www.cnblogs.com/wtao/archive/2011/09/16/2178760.html

 

Get the CPU utilization script (VBS) and save it as CPU vbs:

1 On Error Resume Next
2 Set objProc  = GetObject("winmgmts:\\.\root\cimv2:win32_processor='cpu0'")
3 Wscript. Echo "CPU usage:" & objproc LoadPercentage & "%"

Get the memory usage script (VBS) and save it as RAM vbs:

1 strComputer = "."
2 set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
3 set colOS = objWMI.InstancesOf("Win32_OperatingSystem")
4 for each objOS in colOS
5 strreturn = "total memory:" & round (obyos. Totalvisiblememorysize / 1024) & "MB" & vbcrlf & "available memory:" & round (obyos. Freephysicalmemory / 1024) & "MB" & vbcrlf & "memory usage:" & round (((obyos. Totalvisiblememorysize obyos. Freephysicalmemory) / obyos TotalVisibleMemorySize)*100) & "%"
6 Wscript.Echo strReturn
7 next

Get the disk usage script (VBS) and save it as hard vbs:

1 Set fsoobj = CreateObject("Scripting.FileSystemObject")
 2  DriversInfo = GetDriversInfo
 3  DriversInfo = Replace(DriversInfo, "|", vbCrLf)
 4 sreturn = "hard disk information:" & vbcrlf & driverinfo
 5  Wscript.Echo sReturn
 6 Function GetDriversInfo()
 7 
 8    GetDriversInfo = ""
 9    Set drvObj = fsoobj.Drives
10    For Each D In drvObj
11        Err.Clear
12        If D.DriveLetter <> "A" Then
13            If D.isReady Then
14 getdriverinfo = getdriverinfo & "partition:" & d.driveletter & vbcrlf
15 getdriverinfo = getdriverinfo & "free space:" & CSize (d.freespace) & vbcrlf
16 getdriverinfo = getdriverinfo & "total size:" & CSize (d.totalsize) & vbcrlf
17 getdriverinfo = getdriverinfo & "usage:" & (100 * ((d.totalsize-d.freespace) / d.totalsize)) & "%" & vbcrlf
18                GetDriversInfo = GetDriversInfo & "|"
19              Else
20            End If
21          Else
22        End If
23    Next
24 End Function
25 
26  Function cSize(tSize)
27 
28      If tSize >= 1073741824 Then
29          cSize = Int((tSize / 1073741824) * 1000) / 1000 & " GB"
30        ElseIf tSize >= 1048576 Then
31          cSize = Int((tSize / 1048576) * 1000) / 1000 & " MB"
32        ElseIf tSize >= 1024 Then
33          cSize = Int((tSize / 1024) * 1000) / 1000 & " KB"
34        Else
35          cSize = tSize & "B"
36      End If
37 
38 End Function

Finally, execute the above script in batch and save it as “get CPU, memory and disk utilization. Bat”

1 @echo off
2 echo "getting CPU, memory and disk usage, please wait..."
3 echo CPU information: > info txt
4 cscript //Nologo cpu.vbs >> info.txt
5 echo.>>info.txt
6 echo memory information: > > info txt
7 cscript //Nologo ram.vbs >> info.txt
8 echo.>>info.txt
9 cscript //Nologo hard.vbs >> info.txt

The results are as follows:

1 CPU information:
 2 CPU utilization: 22%
 3 
 4 memory information:
 5 total memory: 12132 MB
 6 memory available: 7354 MB
 7. Memory utilization: 39%
 8 
 9 hard disk information:
Zone 10: C
11 free space: 64.541 GB
12 total size: 102.443 GB
13. Utilization rate: 36.9974772881646%
14 
Zone 15: D
16 available space: 134.282 GB
17 total size: 402.132 GB
18. Utilization rate: 66.6073734064705%
19 
Zone 20: e
21 free space: 47.56 GB
22 total size: 300.003 GB
23. Utilization rate: 84.14686136043%
24 
Zone 25: F
26 free space: 48.774 GB
27 total size: 220.006 GB
28. Utilization rate: 77.8305072014826%

 

Recommended Today

JS generate guid method

JS generate guid method https://blog.csdn.net/Alive_tree/article/details/87942348 Globally unique identification(GUID) is an algorithm generatedBinaryCount Reg128 bitsNumber ofidentifier , GUID is mainly used in networks or systems with multiple nodes and computers. Ideally, any computational geometry computer cluster will not generate two identical guids, and the total number of guids is2^128In theory, it is difficult to make two […]