BOOL DeviceInstalled = FALSE;
DWORD BytesWritten;
DWORD Value;
+ HANDLE hInstallEvent;
HANDLE hPipe = INVALID_HANDLE_VALUE;
LPVOID Environment = NULL;
PROCESS_INFORMATION ProcessInfo;
DPRINT1("Installing: %S\n", DeviceInstance);
- /* Create a random UUID for the named pipe */
+ /* Create a random UUID for the named pipe & event*/
UuidCreate(&RandomUuid);
swprintf(UuidString, L"{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
RandomUuid.Data1, RandomUuid.Data2, RandomUuid.Data3,
RandomUuid.Data4[3], RandomUuid.Data4[4], RandomUuid.Data4[5],
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 */
wcscpy(PipeName, L"\\\\.\\pipe\\PNP_Device_Install_Pipe_0.");
wcscat(PipeName, UuidString);
hPipe = CreateNamedPipeW(PipeName, PIPE_ACCESS_OUTBOUND, PIPE_TYPE_BYTE, 1, 512, 512, 0, NULL);
-
if (hPipe == INVALID_HANDLE_VALUE)
{
DPRINT1("CreateNamedPipeW failed with error %u\n", GetLastError());
}
/* 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);
WriteFile(hPipe, &Value, sizeof(Value), &BytesWritten, NULL);
WriteFile(hPipe, InstallEventName, Value, &BytesWritten, NULL);
/* Wait for newdev.dll to finish processing */
WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
- /* The following check for success is probably not compatible to Windows, but should do its job */
- if (!GetExitCodeProcess(ProcessInfo.hProcess, &Value))
- {
- DPRINT1("GetExitCodeProcess failed with error %u\n", GetLastError());
- goto cleanup;
- }
-
- DeviceInstalled = Value;
+ /* If the event got signalled, this is success */
+ DeviceInstalled = WaitForSingleObject(hInstallEvent, 0) == WAIT_OBJECT_0;
cleanup:
+ if (hInstallEvent)
+ CloseHandle(hInstallEvent);
+
if (hPipe != INVALID_HANDLE_VALUE)
CloseHandle(hPipe);
HANDLE hPipe = INVALID_HANDLE_VALUE;
PWSTR DeviceInstance = NULL;
PWSTR InstallEventName = NULL;
+ HANDLE hInstallEvent;
/* Open the pipe */
hPipe = CreateFileW(lpNamedPipeName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
}
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:
if(hPipe != INVALID_HANDLE_VALUE)