Closed. This question needs to be more focused。它当前不接受答案。












想改善这个问题吗?更新问题,使其仅关注editing this post的一个问题。

4年前关闭。



Improve this question




我有这个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时缺少“等待”部分

谢谢

最佳答案

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

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

10-02 10:36