Windows Media Player 11 SDK Detecting Setup Status for Windows Media SetupĀ 

Windows Media Player SDK banner art

Previous Next

Detecting Setup Status for Windows Media Setup

The following code can be used with the Windows Media Player redistribution packages. The installation status is stored as an HRESULT in the following registry entry:

HKEY_CURRENT_USER\Software\Microsoft\MediaPlayer\Setup, REG_SZ, value InstallResult

The HRESULT value can be used to determine setup success and whether a restart is needed.

Here is example C++ code that could be incorporated into a calling setup application. This code will set the fSuccess and fRebootNeeded variables to true or false, as appropriate, based on the HRESULT value written by Windows Media Player Setup in the component redistribution package.

#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;
 
if( ERROR_SUCCESS == RegOpenKeyExA( 
                         HKEY_CURRENT_USER, 
                         "Software\\Microsoft\\MediaPlayer\\Setup", 
                         0, KEY_QUERY_VALUE, &hKey ))
    {
        char szResult[64];
        DWORD dwResult = sizeof( szResult );
 
if( ERROR_SUCCESS == RegQueryValueExA( 
                         hKey, "InstallResult", NULL, NULL, 
                         (LPBYTE)szResult, &dwResult ) )
        {
            sscanf( szResult, "%x", &dwResult );
            fSuccess = SUCCEEDED( dwResult );
            fRebootNeeded = ( NS_S_REBOOT_REQUIRED == dwResult );
        }
 
        RegCloseKey( hKey );
    }
 
    if( fSuccess )
    {
        printf( "Setup Succeeded..." );
        if( fRebootNeeded )
            printf( "A restart IS required...\n" );
        else
            printf( "A restart IS NOT required...\n" );
    }
    else
    {
        printf( "Setup Failed..." );
        if( fRebootNeeded )
            printf( "A restart IS required...\n" );
        else
            printf( "A restart IS NOT required...\n" );
    }
 
    return 0;
}

See Also

Previous Next