BOOL IsDeviceInstallInProgress(VOID) { typedef DWORD (WINAPI *CMP_WAITNOPENDINGINSTALLEVENTS_PROC)(IN DWORD dwTimeout); CMP_WAITNOPENDINGINSTALLEVENTS_PROC pCMP_WaitNoPendingInstallEvents; HMODULE hModule = GetModuleHandle(TEXT("setupapi.dll")); if(!hModule) { // Should never happen since we're linked to SetupAPI, but... _ASSERTE(FALSE); 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); }
BOOL IsDeviceInstallInProgress(VOID) /*++ Routine Description: This routine dynamically retrieves the entrypoint to a Windows 2000 (and later) Configuration Manager (CM) API that can be used to detect whether there are presently any device installations in-progress. If this API is not available (it may be obsoleted on future releases of the OS), then the API assumes there are no device installations in progress. This is OK, because future versions of the OS will suppress auto-run when "Found New Hardware" wizard is up, thus eliminating the need for apps to do their own checking. Arguments: none Return Value: If there is presently a device installation in progress, the return value is TRUE. If there is not presently a device installation in progress, or we were unsuccessful in retrieving the necessary Configuration Manager API, then the return value is FALSE. --*/ { HMODULE hModule; CMP_WAITNOPENDINGINSTALLEVENTS_PROC pCMP_WaitNoPendingInstallEvents; hModule = GetModuleHandle(L"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 OS that doesn't supply this API. // Trust the OS to suppress autorun when appropriate. // return FALSE; } return (pCMP_WaitNoPendingInstallEvents(0) == WAIT_TIMEOUT); }