[UMPNPMGR][NEWDEV]

- Actually create the "InstallEvent" as an event and use it to communicate success from newdev back to umpnpmgr. This works better than checking the process exit code from rundll32 (which always returns 0).
CORE-9477 #resolve

svn path=/trunk/; revision=67025
This commit is contained in:
Thomas Faber 2015-04-03 18:30:37 +00:00
parent e68fe3a3b4
commit 9b7e229a23
2 changed files with 33 additions and 13 deletions

View file

@ -3016,6 +3016,7 @@ InstallDevice(PCWSTR DeviceInstance, BOOL ShowWizard)
BOOL DeviceInstalled = FALSE; BOOL DeviceInstalled = FALSE;
DWORD BytesWritten; DWORD BytesWritten;
DWORD Value; DWORD Value;
HANDLE hInstallEvent;
HANDLE hPipe = INVALID_HANDLE_VALUE; HANDLE hPipe = INVALID_HANDLE_VALUE;
LPVOID Environment = NULL; LPVOID Environment = NULL;
PROCESS_INFORMATION ProcessInfo; PROCESS_INFORMATION ProcessInfo;
@ -3056,7 +3057,7 @@ InstallDevice(PCWSTR DeviceInstance, BOOL ShowWizard)
DPRINT1("Installing: %S\n", DeviceInstance); DPRINT1("Installing: %S\n", DeviceInstance);
/* Create a random UUID for the named pipe */ /* Create a random UUID for the named pipe & event*/
UuidCreate(&RandomUuid); UuidCreate(&RandomUuid);
swprintf(UuidString, L"{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}", swprintf(UuidString, L"{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
RandomUuid.Data1, RandomUuid.Data2, RandomUuid.Data3, RandomUuid.Data1, RandomUuid.Data2, RandomUuid.Data3,
@ -3064,11 +3065,20 @@ InstallDevice(PCWSTR DeviceInstance, BOOL ShowWizard)
RandomUuid.Data4[3], RandomUuid.Data4[4], RandomUuid.Data4[5], RandomUuid.Data4[3], RandomUuid.Data4[4], RandomUuid.Data4[5],
RandomUuid.Data4[6], RandomUuid.Data4[7]); RandomUuid.Data4[6], RandomUuid.Data4[7]);
/* Create the event */
wcscpy(InstallEventName, L"Global\\PNP_Device_Install_Event_0.");
wcscat(InstallEventName, UuidString);
hInstallEvent = CreateEventW(NULL, TRUE, FALSE, InstallEventName);
if (!hInstallEvent)
{
DPRINT1("CreateEventW('%ls') failed with error %lu\n", InstallEventName, GetLastError());
goto cleanup;
}
/* Create the named pipe */ /* Create the named pipe */
wcscpy(PipeName, L"\\\\.\\pipe\\PNP_Device_Install_Pipe_0."); wcscpy(PipeName, L"\\\\.\\pipe\\PNP_Device_Install_Pipe_0.");
wcscat(PipeName, UuidString); wcscat(PipeName, UuidString);
hPipe = CreateNamedPipeW(PipeName, PIPE_ACCESS_OUTBOUND, PIPE_TYPE_BYTE, 1, 512, 512, 0, NULL); hPipe = CreateNamedPipeW(PipeName, PIPE_ACCESS_OUTBOUND, PIPE_TYPE_BYTE, 1, 512, 512, 0, NULL);
if (hPipe == INVALID_HANDLE_VALUE) if (hPipe == INVALID_HANDLE_VALUE)
{ {
DPRINT1("CreateNamedPipeW failed with error %u\n", GetLastError()); DPRINT1("CreateNamedPipeW failed with error %u\n", GetLastError());
@ -3123,9 +3133,6 @@ InstallDevice(PCWSTR DeviceInstance, BOOL ShowWizard)
} }
/* Pass the data. The following output is partly compatible to Windows XP SP2 (researched using a modified newdev.dll to log this stuff) */ /* Pass the data. The following output is partly compatible to Windows XP SP2 (researched using a modified newdev.dll to log this stuff) */
wcscpy(InstallEventName, L"Global\\PNP_Device_Install_Event_0.");
wcscat(InstallEventName, UuidString);
Value = sizeof(InstallEventName); Value = sizeof(InstallEventName);
WriteFile(hPipe, &Value, sizeof(Value), &BytesWritten, NULL); WriteFile(hPipe, &Value, sizeof(Value), &BytesWritten, NULL);
WriteFile(hPipe, InstallEventName, Value, &BytesWritten, NULL); WriteFile(hPipe, InstallEventName, Value, &BytesWritten, NULL);
@ -3141,16 +3148,13 @@ InstallDevice(PCWSTR DeviceInstance, BOOL ShowWizard)
/* Wait for newdev.dll to finish processing */ /* Wait for newdev.dll to finish processing */
WaitForSingleObject(ProcessInfo.hProcess, INFINITE); WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
/* The following check for success is probably not compatible to Windows, but should do its job */ /* If the event got signalled, this is success */
if (!GetExitCodeProcess(ProcessInfo.hProcess, &Value)) DeviceInstalled = WaitForSingleObject(hInstallEvent, 0) == WAIT_OBJECT_0;
{
DPRINT1("GetExitCodeProcess failed with error %u\n", GetLastError());
goto cleanup;
}
DeviceInstalled = Value;
cleanup: cleanup:
if (hInstallEvent)
CloseHandle(hInstallEvent);
if (hPipe != INVALID_HANDLE_VALUE) if (hPipe != INVALID_HANDLE_VALUE)
CloseHandle(hPipe); CloseHandle(hPipe);

View file

@ -933,6 +933,7 @@ ClientSideInstallW(
HANDLE hPipe = INVALID_HANDLE_VALUE; HANDLE hPipe = INVALID_HANDLE_VALUE;
PWSTR DeviceInstance = NULL; PWSTR DeviceInstance = NULL;
PWSTR InstallEventName = NULL; PWSTR InstallEventName = NULL;
HANDLE hInstallEvent;
/* Open the pipe */ /* Open the pipe */
hPipe = CreateFileW(lpNamedPipeName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); hPipe = CreateFileW(lpNamedPipeName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
@ -983,6 +984,21 @@ ClientSideInstallW(
} }
ReturnValue = DevInstallW(NULL, NULL, DeviceInstance, ShowWizard ? SW_SHOWNOACTIVATE : SW_HIDE); ReturnValue = DevInstallW(NULL, NULL, DeviceInstance, ShowWizard ? SW_SHOWNOACTIVATE : SW_HIDE);
if(!ReturnValue)
{
ERR("DevInstallW failed with error %lu\n", GetLastError());
goto cleanup;
}
hInstallEvent = CreateEventW(NULL, TRUE, FALSE, InstallEventName);
if(!hInstallEvent)
{
TRACE("CreateEventW('%ls') failed with error %lu\n", InstallEventName, GetLastError());
goto cleanup;
}
SetEvent(hInstallEvent);
CloseHandle(hInstallEvent);
cleanup: cleanup:
if(hPipe != INVALID_HANDLE_VALUE) if(hPipe != INVALID_HANDLE_VALUE)