Jump to content
Sign in to follow this  
LisHawj

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

Share this post


Link to post
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

 

Share this post


Link to post
Share on other sites

@LisHawj

Little suggestion...

Since I see that everything in the .vbs file could be done with AutoIt, why don't you convert the .vbs to AutoIt in order to have all your "main" script in one? :)


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites

Changing the scrubber code to spit out a tag file worked for me.  I am going to test changing the RESTART prompt box to some other exit codes as you had mentioned too.  Thank you for the idea.

Share this post


Link to post
Share on other sites

@FrancescoDiMuro

I had thought about that, but my supervisor needed this 2 hours ago.  LOL.  Time permitting, I will likely revisit the idea of converting it over to Autoit.

Thank you,

 

Lishawj 

 

Share this post


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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...