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
            Sleep(100)
        ElseIf ProcessExists($iPID) And $nRegV = "1" Then
            _Restart()
        ElseIf Not ProcessExists($iPID) And $nRegV = "" Then
            _RunOInstall()
        EndIf
    WEnd
EndFunc   ;==>_RunScrubber

Add this picture to hopefully clarified my post.
 

Capture.PNG

Link to comment
Share on other sites

33 minutes ago, LisHawj said:

I cannot find a way to capture or identify the RESTART prompt generated by the Office Scrubber VBS script

post the "scrubber.vbs" and anyone can change the msgbox to an exit code you can use to determine the finish state.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

@argumentum

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
            outFile="C:\Clean\Install\Success.txt"
            Set objFile = objFSO.CreateTextFile(outFile,True)
            objFile.Write "No restart required." & vbCrLf
            objFile.Close
            iError = ERROR_SUCCESS
            Log sTmp & "SUCCESS"
        Else
            Log sTmp & "ERROR"
        End If

    End If
   
    ' Reboot handling
    If fRebootRequired Then
        outFile="C:\Clean\Install\Restart.txt"
        Set objFile = objFSO.CreateTextFile(outFile,True)
        objFile.Write "Restart required." & vbCrLf
        objFile.Close
        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
                    oOS.Reboot()
                Next
            End If
        End If
    End If

    wscript.quit iError
End Sub 'ExitScript

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...