Use Windows.pkg
Use cApplication.pkg

Object oApplication is a cApplication
    Set pbPreserveEnvironment to False
    Set psCompany to "RDC Tools International"
    Set psProduct to "RegCheckChanger"
    Set psVersion to "2012.1"
End_Object

// *** Must be used after the cApplication object!
Use RegCheck2.pkg 

Procedure DoChangeRegistrySettings
    Boolean bReportOnlyState bRegistryChangesNeeded
    Boolean bRegistryChangeFailed bRegistryWriteAccessDenied
    Integer iRetval
    
    Get pbReportOnlyState of ghoRegCheck2 to bReportOnlyState
    Set pbReportOnlyState of ghoRegCheck2 to True
    Send DoCheckRegistrySettings of ghoRegCheck2
    Set pbReportOnlyState of ghoRegCheck2 to bReportOnlyState

    Get pbRegistryChangesNeeded of ghoRegCheck2 to bRegistryChangesNeeded
    
    // Yes, we need to change the registry:
    If (bRegistryChangesNeeded = True) Begin
        // *** Main write message ***
        Send DoWriteRegistrySettings of ghoRegCheck2  
        
        // True if at least on of the registry changes failed.
        Get pbRegistryChangeFailed of ghoRegCheck2 to bRegistryChangeFailed   
        // True if access was denied when trying to write to registry.
        Get pbRegistryWriteAccessDenied of ghoRegCheck2 to bRegistryWriteAccessDenied
        
        // Registry changes failed:
        If (bRegistryChangeFailed = True) Begin
            If (bRegistryWriteAccessDenied = True) Begin
                Send Stop_Box (CS_RegistryAccessDenied * csRegistryChangesNeeded + "\n" + csContactYourSystemAdministrator + csProgramWillBeTerminated)
            End 
            // Else there was some error writing to the registry; see error log file.
            Else Begin
                Send Stop_Box (csErrorWritingToRegistry + "(" + CS_LogFileName + ")"  + "\n" + csProgramWillBeTerminated)
            End
        End 
        
        // Registry changes succeeded:
        Else Begin
            Get YesNo_Box csRegistryChangesDoneReboot to iRetval
            If (iRetval = MBR_Yes) Begin
                Send RebootMachine of ghoRegCheck2
            End                                   
            Else Begin
                Send Info_Box (csManualRebootInfo + csProgramWillBeTerminated)
            End
        End
    End 
    
    // No registry changes necessary:
    Else Begin
        Send Info_Box csNoRegistryChangesNeeded
    End  
    Send Exit_Application
End_Procedure
        
Send DoChangeRegistrySettings
