修复vbs以启动隐藏系统文件检查器

时间:2016-07-22 21:48:06

标签: windows vbscript cmd

我有这个vbs(脚本的一部分由hackoo提供)来启动sfc.exe来修复系统文件,但是我需要添加一些功能,比如消息,我需要在运行时sfc.exe,显示一条消息"等待" (隐藏sfc.exe窗口)和程序结束,退出最后的消息,但脚本不能正常工作(sfc.exe无法隐藏窗口并在结束前显示最终消息)

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时

由于

1 个答案:

答案 0 :(得分:1)

要隐藏控制台,您应该这样写:

False更改为True,等待流程完成,将值1更改为0以隐藏控制台

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