Search code examples
windowsbatch-filevbscriptwsh

How to launch System File Checker tool with vbs


In batch or cmd, sfc.exe run with a simple command:

%windir%\system32\SFC.exe /SCANNOW

How to run this command with .vbs script (x86 x64)??

Thanks


Solution

  • You can do something like this, just give a try !

    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
    Set ws = createobject("wscript.shell")
    MyCommand = "SFC /SCANNOW"
    Execution = ws.run(MyCommand,1,False)