修复vbs以启动隐藏系统文件检查程序 [英] fix vbs to launch hide System File Checker

查看:316
本文介绍了修复vbs以启动隐藏系统文件检查程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

 选项显式
'以管理员身份运行
如果不是WScript.Arguments.Named.Exists(elevate)然后
CreateObject .Application)。ShellExecute WScript.FullName _
,WScript.ScriptFullName& / elevate,,runas,1
WScript.Quit
结束如果
出现错误继续下一个
mensaje = MSGBOX(启动系统文件检查器,vbOKCancel ,System File Checker)
如果mensaje = vbOK则
Dim ws,MyCommand,Execution
设置ws = createobject(wscript.shell)
MyCommand =%windir %\system32 \SFC.exe / SCANNOW
执行= ws.run(MyCommand,1,False)
objshell.run NewPath,vbhide
CALL MSGBOX完成,VBOKONLY,系统文件检查器)
否则
调用MSGBOX(系统文件检查器已取消,VBOKONLY,系统文件检查器)
结束如果
错误GoTo 0

注意:运行隐藏的sfc.exe时缺少部分wait

感谢

解决方案

要隐藏控制台, p>

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

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

您的代码应如下所示:

 选项显式
'以管理员身份运行
如果不是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启动系统文件检查器,vbOKCancel + vbQuestion,系统文件检查器)
如果Question = vbOK then
设置ws = createobject(wscript.shell)
MyCommand = %windir%\system32\SFC.exe / SCANNOW
执行= ws.run(MyCommand,0,True)
如果执行= 0则
调用MSGBOX已经完成,VBOKONLY,系统文件检查器)
否则
调用MSGBOX(系统文件检查器已取消,VBOKONLY,系统文件检查器)
Wscript.quit )
结束如果
否则
调用MSGBOX(系统文件检查程序已取消,VBOKONLY,系统文件检查程序)
Wscript.quit(1)
End If


I have this vbs (part of the script was provided by hackoo) to launch sfc.exe to fix system files, but like I need to add some features, such as a message, and I need while running sfc.exe, display a message "wait" (hiding the sfc.exe window) and the end of the program, exit the final message, but the script does not work well (sfc.exe fails hiding the window and displays the final message before concluding)

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

Note: missing part "wait" while running hidden sfc.exe

Thanks

解决方案

To hide the console you should write it like that :

Change False to True for waiting until the process will finish and the value 1 to 0 to hide the console

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

And your code should look like this one :

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

这篇关于修复vbs以启动隐藏系统文件检查程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆