您的 裝置安裝應用程式 應在執行安裝前,先判斷是否有其他裝置安裝活動正在進行中。 為了做出此判斷,裝置安裝應用程式應呼叫 CMP_WaitNoPendingInstallEvents,通常使用零逾時值。 如果此函式的回傳值顯示其他安裝活動仍在待處理(例如,尋找新硬體精靈可能仍在執行),裝置安裝應用程式應該會退出。
為了讓您的 裝置安裝應用程式 與不支援 CMP_WaitNoPendingInstallEvents的平台相容,應用程式應包含以下程式碼:
BOOL
IsDeviceInstallInProgress (VOID)
{
HMODULE hModule;
CMP_WAITNOPENDINGINSTALLEVENTS_PROC pCMP_WaitNoPendingInstallEvents;
hModule = GetModuleHandle(TEXT("setupapi.dll"));
if(!hModule)
{
// Should never happen since we're linked to SetupAPI, but...
return FALSE;
}
pCMP_WaitNoPendingInstallEvents =
(CMP_WAITNOPENDINGINSTALLEVENTS_PROC)GetProcAddress(hModule,
"CMP_WaitNoPendingInstallEvents");
if(!pCMP_WaitNoPendingInstallEvents)
{
// We're running on a release of the operating system that doesn't supply this function.
// Trust the operating system to suppress AutoRun when appropriate.
return FALSE;
}
return (pCMP_WaitNoPendingInstallEvents(0) == WAIT_TIMEOUT);
}
int
__cdecl
_tmain(IN int argc, IN PTCHAR argv[])
{
if(IsDeviceInstallInProgress()) {
//
// We don't want to start right now. Instead, our
// device co-installer will invoke this application
// (if necessary) during finish-install processing.
//
return -1;
}
.
.
}
使用此程式碼的前提是,若平台不支援 CMP_WaitNoPendingInstallEvents,則在安裝活動進行中時,平台不會啟動自動運行。
關於此程式碼的範例使用,請參閱 Windows Driver Kit (WDK) src\general\toaster 子目錄下的 Toaster 安裝套件。