On Error Resume Next
Dim count
count = 0
set wmi=GetObject("winmgmts:\\.\root\CIMV2")
set wmi2=GetObject("winmgmts:\\.\root\WMI")
set w=wmi.ExecQuery("select * from win32_processor")
b = "CPU名称:"
for each i in w
b = b & vbcrlf & i.Name
next
For j = 1 To 10 step 1 '循环X次,步长为1
j = 1
Wscript.Sleep 2200
set w=wmi2.ExecQuery("select * from MSAcpi_ThermalZoneTemperature")
a = b & vbcrlf & "CPU温度:"
for each i in w
a=a & vbcrlf & (i.CurrentTemperature - 2732)/10.0
c=(i.CurrentTemperature - 2732)/10.0
next
'createobject("wscript.shell").popup c,1,"CPU温度",4096+64
Set FSO = CreateObject("Scripting.FileSystemObject")
'指定文件夹
FileUrl = createobject("Scripting.FileSystemObject").GetFile(Wscript.ScriptFullName).ParentFolder.Path
'MsgBox FileUrl
Set f = FSO.GetFolder(FileUrl)
mytime = Replace(time(),":","-")
For Each item in f.Files
If Left(item.name, 6) = "CPU温度-" Then
'MsgBox item.name
if count = 0 then
item.Name = "CPU温度-" & c & "℃("&mytime&").txt"
else
FSO.DeleteFile(item.name)
end if
count = 1
set f = FSO.opentextfile("CPU温度-" & c & "℃("&mytime&").txt",2,true)
f.write "CPU相关信息" & vbcrlf & vbcrlf & a & vbcrlf & "当前系统时间" & vbcrlf & mytime
f.close
End If
Next
if count = 0 then
set f = FSO.opentextfile("CPU温度-" & c & "℃("&mytime&").txt",2,true)
f.write "CPU温度:" & vbcrlf & vbcrlf & a & mytime
f.close
end if
count = 0
Next
Set f = Nothing
Set fso = Nothin
先上代码,话不多说,看效果: