Compartir a través de


Detección del estado del programa de instalación

Cuando el ejecutable de redistribución se ejecuta en un equipo, registra su estado de instalación en el Registro como un valor HRESULT . El estado de instalación se almacena en la entrada del Registro InstallResult en la siguiente subclave:

HKEY_CURRENT_USER\Software\Microsoft\MediaPlayer\Setup

La entrada del Registro InstallResult tiene el siguiente formato.

Nombre Tipo Valor
InstallResult REG_DWORD HrESULT que indica si Reproductor multimedia de Windows instalación se realizó correctamente y si se necesita un reinicio.

 

El código siguiente establecerá las variables fSucess y fRebootNeeded enTrue o False, según corresponda, en función del valor HRESULT escrito por el programa de instalación de Windows Media en el paquete de redistribución de componentes.

#include <windows.h>
#include <stdio.h>

// If NS_S_REBOOT_REQUIRED is undefined, use 0xD2AF9.
#ifndef NS_S_REBOOT_REQUIRED
#define NS_S_REBOOT_REQUIRED       0xd2af9
#endif
  
int main( void )
{
    HKEY hKey = NULL;
    BOOL fSuccess = FALSE;
    BOOL fRebootNeeded = FALSE;

    LONG lResult = RegOpenKeyEx( 
        HKEY_CURRENT_USER, 
        TEXT("Software\\Microsoft\\MediaPlayer\\Setup"), 
        0, 
        KEY_QUERY_VALUE, 
        &hKey 
        );

    if ( lResult == ERROR_SUCCESS )
    {
        DWORD dwRegType = 0;   // Registry value type.
        DWORD dwValue = 0;     // Registry value.
        DWORD cbValue = sizeof( dwValue );  // Size of the value in bytes.

        lResult = RegQueryValueEx( 
            hKey, 
            TEXT("InstallResult"), 
            NULL, 
            &dwRegType, 
            (LPBYTE)&dwValue, 
            &cbValue
            );

        if( lResult == ERROR_SUCCESS )
        {
            if (dwRegType == REG_DWORD)
            {
                fSuccess = SUCCEEDED( dwValue );
                fRebootNeeded = ( NS_S_REBOOT_REQUIRED == dwValue );
            }
        }

        RegCloseKey( hKey );
    }

    if( fSuccess )
    {
        printf( "Setup succeeded." );
    }
    else
    {
        printf( "Setup failed." );
    }

    if( fRebootNeeded )
    {
        printf( "A reboot IS required.\n" );
    }
    else
    {
        printf( "A reboot IS NOT required.\n" );
    }
 
    return 0;
}

Redistribución de software