Problem with a driver removal

I’ve got a sample filter driver that uses an application program to remove
itself. Sometimes the system will remove my entry from the LowerFilters
section and sometimes it doesn’t. I haven’t been able to reproduce this on
a consistent basis (most likely timing related) and would like to know if
anyone else has experienced this or if I could enable any SetupAPI Logging
to reveal why the removal doesn’t happen.

In the INF file I’ve specified a remove section as follows:

[DefaultUninstall]
DelReg = MyDriverUninstallDriverDelReg
DelFiles = MyDriver.DelFiles

[DefaultUninstall.Services]
DelService = mydriver

[MyDriverUninstallDriverDelReg]
HKLM,System\CurrentControlSet\Control\Class{4D36E967-E325-11CE-BFC1-08002BE10318},
LowerFilters, %REG_MULTI_SZ_DELETE%, mydriver

[MyDriver.DelFiles]
mydriver.sys,1

Here is the code in the application program that calls this section:

int
myDriverInstallFromInfSection(
IN LPTSTR infFile,
IN LPTSTR sectionName
)
{
HINF hInf = NULL;
DWORD dwError = NO_ERROR;

//
// Open a handle to the INF file
//
hInf = SetupOpenInfFile(infFile, NULL, INF_STYLE_WIN4, NULL);

if (hInf != INVALID_HANDLE_VALUE)
{

LPVOID queueContext = NULL;

//
// Initialize the default queue callback routine (no UI)
//
queueContext = SetupInitDefaultQueueCallbackEx(NULL,
INVALID_HANDLE_VALUE, 0, 0, NULL);
if (queueContext) {

//
// Let Setup execute the sectionName Section
//
if (SetupInstallFromInfSection(NULL,
hInf,
sectionName,
SPINST_REGISTRY | SPINST_FILES,
NULL,
NULL,
SP_COPY_FORCE_NEWER,
SetupDefaultQueueCallback,
queueContext,
NULL,
NULL)) {

TCHAR servicesSection[MAX_PATH];

_tcscpy(servicesSection, sectionName);
_tcscat(servicesSection, SERVICES_SECTION);

//
// Let Setup execute the [sectionName.Services] Section
//
if (SetupInstallServicesFromInfSection(hInf,
servicesSection, 0)) {

//
// The section was successfully installed
//

} else {
dwError = GetLastError();
}

} else {
dwError = GetLastError();
}

} else {
dwError = ERROR_NOT_ENOUGH_MEMORY;
}

//
// Close the INF handle
//
SetupCloseInfFile(hInf);

} else {
dwError = GetLastError();
debugPrint(DEBUG_NOTICE, “cmdInstallFromInfSection: unable to open INF
file ‘%ws’\r\n”, infFile);
}

if(dwError == NO_ERROR)
{
return(EXIT_OK);
}
else
{
debugPrint(DEBUG_NOTICE, “cmdInstallFromInfSection: Error 0x%x\r\n”,
dwError);
return(EXIT_FAIL);
}
}

Regards,
Bob