Jump to content

How to identify a RESTART prompt from a VBS script.

Recommended Posts

The following snip of code is from a much larger piece I am working on.  I am having much difficulty with the following piece of code because I cannot find a way to capture or identify the RESTART prompt generated by the Office Scrubber VBS script.  Here are the two scenario that usually occur:

Scenario 1:  A larger piece of my code launch the Office Scrubber from Microsoft (OffScrubC2R_212.vbs).  The scrubber completes successfully or with minimal error and does not require a restart.  The scrubber .vbs script ends and I am able to capture the process ID termination.  After the process ID terminates, I run another piece of code to launch the Office installation routine.  This piece of my code works as intended.

Scenario 2: Same as above, but the Office Scrubber runs into issues and kicks up a RESTART prompt.  The .vbs/wscript process does not end and instead generate a GUI dialog prompt to restart or cancel the restart.  It all seems so easy, but I am unable to capture the restart prompt.  Below is what I have tried so far.

1. The restart prompt is usually tag by a registry key at \\HLKM\Software\Microsoft\Office\15.0\CleanC2R.  However, because the process does not end, I don't know when to check if the registry key exists.  If the key exists, I could write an IF/ELSE.

2. I have tried to read the log file generated by the Office Scrubber for the termination result, but the returned results are never the same.  The return value varies even for success/incomplete scrubbing of the Office installation.

Than you for the help.

Here is my sample code so far.

Local $sWscript = "OffScrubC2R_212.vbs"
Local $sLog = "/Log C:\Log.txt"

Func _RunScrubber()
    $iPID = ShellExecute($sWscript, $sLog, "")
    While 1
        $nRegV = RegRead("\\HLKM64\SOFTWARE\Microsoft\Office\15.0\CleanC2R", "Rerun")
        If ProcessExists($iPID) Or $nRegV <> "1" Then
        ElseIf ProcessExists($iPID) And $nRegV = "1" Then
        ElseIf Not ProcessExists($iPID) And $nRegV = "" Then
EndFunc   ;==>_RunScrubber

Add this picture to hopefully clarified my post.


Link to post
Share on other sites


Great idea!  I have added the following .vbs codes to the scrubber exit script so I can watch for the file creation.  Testing and will report back.

sTmp = "ReturnErrorOrSuccess switch has been set. The current value return code translates to: "
        If fOverallSuccess Then
            Set objFile = objFSO.CreateTextFile(outFile,True)
            objFile.Write "No restart required." & vbCrLf
            iError = ERROR_SUCCESS
            Log sTmp & "SUCCESS"
            Log sTmp & "ERROR"
        End If

    End If
    ' Reboot handling
    If fRebootRequired Then
        Set objFile = objFSO.CreateTextFile(outFile,True)
        objFile.Write "Restart required." & vbCrLf
        sPrompt = "In order to complete uninstall, a system reboot is necessary. Would you like to reboot now?"
        If NOT fQuiet Then
            If MsgBox(sPrompt, vbYesNo, SCRIPTNAME & " - Reboot Required") = VB_YES Then
                Dim colOS, oOS
                Dim oWmiReboot
                Set oWmiReboot = GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}!\\.\root\cimv2")
                Set colOS = oWmiReboot.ExecQuery ("Select * from Win32_OperatingSystem")
                For Each oOS in colOS
            End If
        End If
    End If

    wscript.quit iError
End Sub 'ExitScript


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...