日志磁盘清理VBScript
所以我有一个运行磁盘清理的小脚本,但我想记录这个。有没有可能通过f.writeline或其他方式?我已经尝试添加一些写行,但没有效果,所以我删除了这些日志磁盘清理VBScript,vbscript,Vbscript,所以我有一个运行磁盘清理的小脚本,但我想记录这个。有没有可能通过f.writeline或其他方式?我已经尝试添加一些写行,但没有效果,所以我删除了这些 Option Explicit On Error Resume Next SetRegKeys DoCleanup Sub DoCleanup() Dim WshShell Set WshShell=CreateObject("WScript.Shell") WshShell.Run "C:\WINDOWS\SYSTEM32\
Option Explicit
On Error Resume Next
SetRegKeys
DoCleanup
Sub DoCleanup()
Dim WshShell
Set WshShell=CreateObject("WScript.Shell")
WshShell.Run "C:\WINDOWS\SYSTEM32\cleanmgr /sagerun:1"
End Sub
Sub SetRegKeys
Dim strKeyPath
Dim strComputer
Dim objReg
Dim arrSubKeys
Dim SubKey
Dim strValueName
Dim fso
Const HKLM=&H80000002
strKeyPath="SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches"
strComputer="."
strValueName="StateFlags0001"
Set objReg=GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
objReg.Enumkey HKLM ,strKeyPath,arrSubKeys
For Each SubKey In arrSubKeys
objReg.SetDWORDValue HKLM,strKeyPath & "\" & SubKey,strValueName,2
Next
End Sub
谢谢 我有一个标准子例程,用于记录到输出文件(脚本顶部指定的路径“logfileName”),该文件还将时间附加到每一行:
Sub Logwrite (aMsg)
Dim a
Const ForAppending = 8
' This Appends a line of text to a Logwrite file
' creating it if required
If Len(aMsg) = 0 Then
If fso.FileExists(logfileName) Then fso.DeleteFile(logfileName)
Exit Sub
End If
Set a = fso.OpenTextFile(logfileName, ForAppending, TRUE, 0)
a.WriteLine(Now() & " -- " & aMsg)
a.Close
Set a = Nothing
End Sub
例如,可以在For Each循环中调用子例程,并且可以指定记录的消息:
For Each SubKey In arrSubKeys
objReg.SetDWORDValue HKLM,strKeyPath & "\" & SubKey,strValueName,2
Logwrite "Set value for " & strKeyPath & "\" & SubKey & " to " & strValueName
Next
请注意,如果我想删除上一个文件(如果它存在),那么我将首先调用脚本顶部的子例程,并显示一条空白消息,以记录--Logwrite”“
,这将告诉它删除上一个日志文件
希望这有帮助 嘿,谢谢你的帮助!到目前为止,我已将您的脚本添加到我的脚本中,但它无法工作,我已将“logfilename”更改为“C:\Log.txt”。我做错了什么?有人能帮我吗?问候