2014-02-05 45 views
0

我在尋找被刪除的文件exe文件下面具體尺寸只是在驅動器C:/,但沒有被刪除的文件的文件夾,筆者在驅動器C:/刪除的文件exe文件下面具體尺寸在驅動器C:/

我有代碼在所有驅動器d vbsript工作:/ 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 
+0

試運行具有管理員權限的腳本(右鍵單擊並以「以管理員身份運行」) –

+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 
+0

我的腳本在C:\ WINDOWS \ Delete.vbs中,所以我如何以管理員身份運行腳本 –

+0

我有發佈你需要的完整文件... – KekuSemau

+0

謝謝^^但文件exe不要刪除大小450 kb沒有任何更改 –