2016-07-22 70 views
2

我有這個vbs(腳本的一部分是由hackoo提供)啓動sfc.exe修復系統文件,但就像我需要添加一些功能,如消息和我需要在運行sfc.exe時,顯示一條消息「等待」(隱藏sfc.exe窗口)並結束程序,退出最終消息,但腳本不能正常工作(sfc.exe無法隱藏窗口並顯示在結束前的最後消息)修復vbs啓動隱藏系統文件檢查器

Option Explicit 
' Run as Admin 
    If Not WScript.Arguments.Named.Exists("elevate") Then 
    CreateObject("Shell.Application").ShellExecute WScript.FullName _ 
, WScript.ScriptFullName & " /elevate", "", "runas", 1 
WScript.Quit 
End If 
On Error Resume next 
mensaje = MSGBOX ("Start System File Checker", vbOKCancel, "System File Checker") 
If mensaje = vbOK Then 
Dim ws,MyCommand,Execution 
Set ws = createobject("wscript.shell") 
MyCommand = "%windir%\system32\SFC.exe /SCANNOW" 
Execution = ws.run(MyCommand,1,False) 
objshell.run NewPath,vbhide 
CALL MSGBOX ("System File Checker has finished", VBOKONLY, "System File Checker") 
Else 
CALL MSGBOX ("System File Checker has been canceled", VBOKONLY, "System File Checker") 
End If 
On Error GoTo 0 

注:缺少的一部分 「等」,同時運行隱藏SFC.EXE

感謝

+0

如果有疑問,請閱讀[documentation](https://msdn.microsoft.com/en-us/library/d5fk67ky%28 V = vs.84%29.aspx)。 –

+0

你想用這行做什麼'objshell.run NewPath,vbhide'沒有提及objshell或NewPath – dbmitch

+0

而這個'Execution = ws.run(MyCommand,1,False)'不等待返回 - 所以它正在做你正在告訴它的東西。 – dbmitch

回答

1

要隱藏控制檯,你應該把它寫這樣的:

變化FalseTrue等待,直到過程將結束,價值10隱藏控制檯

Execution = ws.run(MyCommand,0,True) 

您的代碼應看起來像這樣:

Option Explicit 
' Run as Admin 
If Not WScript.Arguments.Named.Exists("elevate") Then 
    CreateObject("Shell.Application").ShellExecute WScript.FullName _ 
    , WScript.ScriptFullName & " /elevate", "", "runas", 1 
    WScript.Quit 
End If 
Dim ws,MyCommand,Execution,Question 
Question = MSGBOX ("Did you want to start the System File Checker ?", vbOKCancel+vbQuestion, "System File Checker") 
If Question = vbOK Then 
    Set ws = createobject("wscript.shell") 
    MyCommand = "%windir%\system32\SFC.exe /SCANNOW" 
    Execution = ws.run(MyCommand,0,True) 
    If Execution = 0 Then 
     Call MSGBOX ("System File Checker has finished", VBOKONLY, "System File Checker") 
    Else 
     Call MSGBOX ("System File Checker has been canceled", VBOKONLY, "System File Checker") 
     Wscript.quit(1) 
    End If 
Else 
    Call MSGBOX ("System File Checker has been canceled", VBOKONLY, "System File Checker") 
    Wscript.quit(1) 
End If 
+0

非常好的hackoo,但是在運行隱藏的sfc時缺少「Wait ...」的部分 – BrianC