Partilhar via


Detetando o status da instalação

[A funcionalidade associada a esta página, Windows Media Format 11 SDK, é uma funcionalidade herdada. Foi substituído pelo Source Reader e pelo Sink Writer. O Source Reader e o Sink Writer foram otimizados para Windows 10 e Windows 11. A Microsoft recomenda vivamente que o novo código utilize do Leitor de Origem e do Gravador de Separadores em vez de SDK do Windows Media Format 11, sempre que possível. A Microsoft sugere que o código existente que usa as APIs herdadas seja reescrito para usar as novas APIs, se possível.]

Quando o executável de redistribuição é executado num computador, ele registra o seu estado de instalação no registo como um valor de HRESULT. O status da instalação é armazenado na entrada do Registro InstallResult na seguinte subchave:

HKEY_CURRENT_USER\Software\Microsoft\MediaPlayer\Setup

A entrada de registo InstallResult tem o seguinte formato.

Nome Tipo Valor
ResultadoDaInstalação REG_DWORD Um HRESULT que indica se a instalação do Windows Media Player foi bem-sucedida e se uma reinicialização é necessária.

 

O código a seguir definirá as variáveis fSucess e fRebootNeeded como True ou False, conforme apropriado, com base no valor HRESULT gravado pela instalação do Windows Media no pacote de redistribuição 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;
}

Redistribuição de Software