Rilevamento dello stato dell'installazione
[La funzionalità associata a questa pagina, Windows Media Format 11 SDK, è una funzionalità legacy. È stata sostituita da lettore di origine e writer sink. Lettore di origine e Scrittore di destinazione sono stati ottimizzati per Windows 10 e Windows 11. Microsoft consiglia vivamente di utilizzare Source Reader e Sink Writer invece di Windows Media Format 11 SDKquando possibile, nel nuovo codice. Microsoft suggerisce che il codice esistente che usa le API legacy venga riscritto per usare le nuove API, se possibile.
Quando il file eseguibile di ridistribuzione viene eseguito in un computer, registra lo stato di installazione nel Registro di sistema come valore HRESULT. Lo stato dell'installazione viene archiviato nella voce del Registro di sistema InstallResult nella sottochiave seguente:
HKEY_CURRENT_USER\Software\Microsoft\MediaPlayer\Setup
La voce del Registro di sistema InstallResult ha il formato seguente.
Nome | Digitare | Valore |
---|---|---|
RisultatoInstallazione | REG_DWORD | Un HRESULT che indica se l'installazione di Windows Media Player è riuscita e se è necessario un riavvio. |
Il codice seguente imposta le variabili fSucess e fRebootNeeded su True o False, a seconda del valore HRESULT scritto dal programma di installazione di Windows Media nel pacchetto di ridistribuzione dei componenti, come appropriato.
#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;
}
Argomenti correlati