检测安装程序状态
当重新分发可执行文件在计算机上运行时,它会在注册表中将其安装状态记录为 HRESULT 值。 安装状态存储在 InstallResult 注册表项的以下子项中:
HKEY_CURRENT_USER\Software\Microsoft\MediaPlayer\Setup
InstallResult 注册表项具有以下形式。
名称 | 类型 | 值 |
---|---|---|
InstallResult | REG_DWORD | 一个 HRESULT,指示Windows 媒体播放器安装是否成功以及是否需要重启。 |
以下代码将根据 Windows Media 安装程序在组件重新分发包中写入的 HRESULT 值,根据需要将 fSucess 和 fRebootNeeded 变量设置为 True 或 False。
#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;
}
相关主题