在驱动器c中删除的文件exe低于特定大小:/

时间:2014-02-05 14:10:43

标签: vbscript

我正在寻找驱动器c:/但在驱动器c的作者文件夹中没有已删除文件的已删除文件exe低于特定大小:/

我的代码vbsript在所有驱动器中工作d:/ e:/ f:/仅在c:/不起作用因为c:/系统驱动器我认为

'Here we set your global variables. These values
'don't change during the runtime of your script.
Set oFSO = CreateObject("Scripting.FileSystemObject")
sDirectoryPath = "c:\"


RecurseFolders sDirectoryPath

Sub RecurseFolders(sFolder)
  'Here we set the oFolder object, note that it's
  'variable scope is within this sub, so you can
  'set it many times and it's value will only be
  'that of the sub that's currently running.
  Set oFolder = oFSO.GetFolder(sFolder)


  'Here we are looping through every file in the
  'directory path.
  For Each oFile In oFolder.Files
    'This just checks for a file size less than 450Kb
    If oFile.Size < 450000 And Right(LCase(oFile.Name),3) = "exe" Then
      oFile.Delete True
    End If
  Next

End Sub

'When calling subs you don't need to set their value
'to a variable name, and you don't use parenthesis.


'Clean up
Set oFSO = Nothing

1 个答案:

答案 0 :(得分:0)

您可以通过另一个vbs调用以管理员身份运行脚本 这是一个让脚本再次使用权限调用自身的便捷方式(当然它仍会触发提示)

Option Explicit
Dim App
Dim wsh

Set App = CreateObject("Shell.Application")
If WScript.Arguments.length =0 then
    App.ShellExecute "wscript.exe", """" & WScript.ScriptFullName & """ uac", _
    "", "runas", 1
Else
    ' the main script in here
    ' ...
End If

所以,这将是你的整个脚本:

Option Explicit
Dim App
Dim wsh
Dim oFSO, sDirectoryPath

    Set App = CreateObject("Shell.Application")
    If WScript.Arguments.length =0 then
        App.ShellExecute "wscript.exe", """" & WScript.ScriptFullName & """ uac", _
        "", "runas", 1
    Else
        Set oFSO = CreateObject("Scripting.FileSystemObject")
        sDirectoryPath = "C:\"
        RecurseFolders sDirectoryPath
        Set oFSO = Nothing
    End If


Sub RecurseFolders(sFolder)
    dim oFolder, oFile
    Set oFolder = oFSO.GetFolder(sFolder)
    For Each oFile In oFolder.Files
        If oFile.Size < 450000 And Right(LCase(oFile.Name),3) = "exe" Then
            oFile.Delete True
        End If
    Next
End Sub