3 * Copyright (C) 2005 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS kernel
22 * FILE: services/umpnpmgr/umpnpmgr.c
23 * PURPOSE: User-mode Plug and Play manager
24 * PROGRAMMER: Eric Kohl
25 * Hervé Poussineau (hpoussin@reactos.org)
28 /* INCLUDES *****************************************************************/
29 #define WIN32_NO_STATUS
34 #include <umpnpmgr/sysguid.h>
46 /* GLOBALS ******************************************************************/
49 ServiceMain(DWORD argc
, LPTSTR
*argv
);
51 static SERVICE_TABLE_ENTRY ServiceTable
[2] =
53 {TEXT("PlugPlay"), ServiceMain
},
57 static WCHAR szRootDeviceId
[] = L
"HTREE\\ROOT\\0";
59 static HKEY hEnumKey
= NULL
;
60 static HKEY hClassKey
= NULL
;
62 static HANDLE hUserToken
= NULL
;
63 static HANDLE hInstallEvent
= NULL
;
66 /* FUNCTIONS *****************************************************************/
69 RpcServerThread(LPVOID lpParameter
)
73 DPRINT("RpcServerThread() called\n");
75 Status
= RpcServerUseProtseqEpW(L
"ncacn_np",
78 NULL
); // Security descriptor
79 if (Status
!= RPC_S_OK
)
81 DPRINT1("RpcServerUseProtseqEpW() failed (Status %lx)\n", Status
);
85 Status
= RpcServerRegisterIf(pnp_v1_0_s_ifspec
,
88 if (Status
!= RPC_S_OK
)
90 DPRINT1("RpcServerRegisterIf() failed (Status %lx)\n", Status
);
94 Status
= RpcServerListen(1,
97 if (Status
!= RPC_S_OK
)
99 DPRINT1("RpcServerListen() failed (Status %lx)\n", Status
);
103 DPRINT("RpcServerThread() done\n");
109 void __RPC_FAR
* __RPC_USER
midl_user_allocate(size_t len
)
111 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
115 void __RPC_USER
midl_user_free(void __RPC_FAR
* ptr
)
117 HeapFree(GetProcessHeap(), 0, ptr
);
121 static CONFIGRET WINAPI
122 NtStatusToCrError(NTSTATUS Status
)
126 case STATUS_NO_SUCH_DEVICE
:
127 return CR_NO_SUCH_DEVINST
;
130 /* FIXME: add more mappings */
131 DPRINT1("Unable to map status 0x%08lx\n", Status
);
139 PNP_GetVersion(handle_t BindingHandle
,
140 unsigned short *Version
)
149 PNP_GetGlobalState(handle_t BindingHandle
,
150 unsigned long *State
,
153 *State
= CM_GLOBAL_STATE_CAN_DO_UI
| CM_GLOBAL_STATE_SERVICES_AVAILABLE
;
160 PNP_InitDetection(handle_t BindingHandle
)
162 DPRINT("PNP_InitDetection() called\n");
169 PNP_ReportLogOn(handle_t BindingHandle
,
171 unsigned long ProcessId
)
175 DPRINT1("PNP_ReportLogOn(%lu, %lu) called\n", Admin
, ProcessId
);
177 /* Get the users token */
178 hProcess
= OpenProcess(PROCESS_ALL_ACCESS
,
181 if (hProcess
!= NULL
)
183 if (hUserToken
!= NULL
)
185 CloseHandle(hUserToken
);
189 OpenProcessToken(hProcess
,
192 CloseHandle(hProcess
);
195 /* Trigger the installer thread */
196 if (hInstallEvent
!= NULL
)
197 SetEvent(hInstallEvent
);
205 PNP_ValidateDeviceInstance(handle_t BindingHandle
,
206 wchar_t *DeviceInstance
,
209 CONFIGRET ret
= CR_SUCCESS
;
210 HKEY hEnumKey
= NULL
;
211 HKEY hDeviceKey
= NULL
;
213 DPRINT("PNP_ValidateDeviceInstance(%S %lx) called\n",
214 DeviceInstance
, Flags
);
216 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
217 L
"System\\CurrentControlSet\\Enum",
222 DPRINT("Could not open the Enum Key!\n");
227 if (RegOpenKeyExW(hEnumKey
,
233 DPRINT("Could not open the Device Key!\n");
234 ret
= CR_NO_SUCH_DEVNODE
;
238 /* FIXME: add more tests */
241 if (hDeviceKey
!= NULL
)
242 RegCloseKey(hDeviceKey
);
244 if (hEnumKey
!= NULL
)
245 RegCloseKey(hEnumKey
);
247 DPRINT("PNP_ValidateDeviceInstance() done (returns %lx)\n", ret
);
255 PNP_GetRootDeviceInstance(handle_t BindingHandle
,
256 wchar_t *DeviceInstance
,
257 unsigned long Length
)
259 CONFIGRET ret
= CR_SUCCESS
;
261 DPRINT("PNP_GetRootDeviceInstance() called\n");
263 if (Length
< lstrlenW(szRootDeviceId
) + 1)
265 ret
= CR_BUFFER_SMALL
;
269 lstrcpyW(DeviceInstance
,
273 DPRINT("PNP_GetRootDeviceInstance() done (returns %lx)\n", ret
);
281 PNP_GetRelatedDeviceInstance(handle_t BindingHandle
,
282 unsigned long Relationship
,
284 wchar_t *RelatedDeviceId
,
285 unsigned long Length
,
288 PLUGPLAY_CONTROL_RELATED_DEVICE_DATA PlugPlayData
;
289 CONFIGRET ret
= CR_SUCCESS
;
292 DPRINT("PNP_GetRelatedDeviceInstance() called\n");
293 DPRINT(" Relationship %ld\n", Relationship
);
294 DPRINT(" DeviceId %S\n", DeviceId
);
296 RtlInitUnicodeString(&PlugPlayData
.TargetDeviceInstance
,
299 PlugPlayData
.Relation
= Relationship
;
301 PlugPlayData
.RelatedDeviceInstance
.Length
= 0;
302 PlugPlayData
.RelatedDeviceInstance
.MaximumLength
= Length
;
303 PlugPlayData
.RelatedDeviceInstance
.Buffer
= RelatedDeviceId
;
305 Status
= NtPlugPlayControl(PlugPlayControlGetRelatedDevice
,
306 (PVOID
)&PlugPlayData
,
307 sizeof(PLUGPLAY_CONTROL_RELATED_DEVICE_DATA
));
308 if (!NT_SUCCESS(Status
))
310 ret
= NtStatusToCrError(Status
);
313 DPRINT("PNP_GetRelatedDeviceInstance() done (returns %lx)\n", ret
);
314 if (ret
== CR_SUCCESS
)
316 DPRINT("RelatedDevice: %wZ\n", &PlugPlayData
.RelatedDeviceInstance
);
325 PNP_EnumerateSubKeys(handle_t BindingHandle
,
326 unsigned long Branch
,
329 unsigned long Length
,
330 unsigned long *RequiredLength
,
333 CONFIGRET ret
= CR_SUCCESS
;
337 DPRINT("PNP_EnumerateSubKeys() called\n");
341 case PNP_BRANCH_ENUM
:
345 case PNP_BRANCH_CLASS
:
353 *RequiredLength
= Length
;
354 dwError
= RegEnumKeyExW(hKey
,
362 if (dwError
!= ERROR_SUCCESS
)
364 ret
= (dwError
== ERROR_NO_MORE_ITEMS
) ? CR_NO_SUCH_VALUE
: CR_FAILURE
;
371 DPRINT("PNP_EnumerateSubKeys() done (returns %lx)\n", ret
);
379 PNP_GetDeviceListSize(handle_t BindingHandle
,
381 unsigned long *Length
,
384 DPRINT("PNP_GetDeviceListSize() called\n");
395 PNP_GetDepth(handle_t BindingHandle
,
396 wchar_t *DeviceInstance
,
397 unsigned long *Depth
,
400 PLUGPLAY_CONTROL_DEPTH_DATA PlugPlayData
;
401 CONFIGRET ret
= CR_SUCCESS
;
404 DPRINT("PNP_GetDepth() called\n");
406 RtlInitUnicodeString(&PlugPlayData
.DeviceInstance
,
409 Status
= NtPlugPlayControl(PlugPlayControlGetDeviceDepth
,
410 (PVOID
)&PlugPlayData
,
411 sizeof(PLUGPLAY_CONTROL_DEPTH_DATA
));
412 if (NT_SUCCESS(Status
))
414 *Depth
= PlugPlayData
.Depth
;
418 ret
= NtStatusToCrError(Status
);
421 DPRINT("PNP_GetDepth() done (returns %lx)\n", ret
);
429 PNP_GetDeviceRegProp(handle_t BindingHandle
,
430 wchar_t *DeviceInstance
,
431 unsigned long Property
,
432 unsigned long *DataType
,
434 unsigned long *TransferLen
,
435 unsigned long *Length
,
438 PLUGPLAY_CONTROL_PROPERTY_DATA PlugPlayData
;
439 CONFIGRET ret
= CR_SUCCESS
;
440 LPWSTR lpValueName
= NULL
;
444 DPRINT("PNP_GetDeviceRegProp() called\n");
448 case CM_DRP_DEVICEDESC
:
449 lpValueName
= L
"DeviceDesc";
452 case CM_DRP_HARDWAREID
:
453 lpValueName
= L
"HardwareID";
456 case CM_DRP_COMPATIBLEIDS
:
457 lpValueName
= L
"CompatibleIDs";
461 lpValueName
= L
"Service";
465 lpValueName
= L
"Class";
468 case CM_DRP_CLASSGUID
:
469 lpValueName
= L
"ClassGUID";
473 lpValueName
= L
"Driver";
476 case CM_DRP_CONFIGFLAGS
:
477 lpValueName
= L
"ConfigFlags";
481 lpValueName
= L
"Mfg";
484 case CM_DRP_FRIENDLYNAME
:
485 lpValueName
= L
"FriendlyName";
488 case CM_DRP_LOCATION_INFORMATION
:
489 lpValueName
= L
"LocationInformation";
492 case CM_DRP_PHYSICAL_DEVICE_OBJECT_NAME
:
496 case CM_DRP_CAPABILITIES
:
497 lpValueName
= L
"Capabilities";
500 case CM_DRP_UI_NUMBER
:
504 case CM_DRP_UPPERFILTERS
:
505 lpValueName
= L
"UpperFilters";
508 case CM_DRP_LOWERFILTERS
:
509 lpValueName
= L
"LowerFilters";
512 case CM_DRP_BUSTYPEGUID
:
516 case CM_DRP_LEGACYBUSTYPE
:
520 case CM_DRP_BUSNUMBER
:
524 case CM_DRP_ENUMERATOR_NAME
:
529 return CR_INVALID_PROPERTY
;
532 DPRINT("Value name: %S\n", lpValueName
);
536 /* Retrieve information from the Registry */
537 if (RegOpenKeyExW(hEnumKey
,
542 return CR_INVALID_DEVNODE
;
544 if (RegQueryValueExW(hKey
,
550 ret
= CR_REGISTRY_ERROR
;
552 /* FIXME: Check buffer size */
558 /* Retrieve information from the Device Node */
559 RtlInitUnicodeString(&PlugPlayData
.DeviceInstance
,
561 PlugPlayData
.Buffer
= Buffer
;
562 PlugPlayData
.BufferSize
= *TransferLen
;
567 case CM_DRP_PHYSICAL_DEVICE_OBJECT_NAME
:
568 PlugPlayData
.Property
= DevicePropertyPhysicalDeviceObjectName
;
571 case CM_DRP_UI_NUMBER
:
572 PlugPlayData
.Property
= DevicePropertyUINumber
;
575 case CM_DRP_BUSTYPEGUID
:
576 PlugPlayData
.Property
= DevicePropertyBusTypeGuid
;
579 case CM_DRP_LEGACYBUSTYPE
:
580 PlugPlayData
.Property
= DevicePropertyLegacyBusType
;
583 case CM_DRP_BUSNUMBER
:
584 PlugPlayData
.Property
= DevicePropertyBusNumber
;
587 case CM_DRP_ENUMERATOR_NAME
:
588 PlugPlayData
.Property
= DevicePropertyEnumeratorName
;
593 return CR_INVALID_PROPERTY
;
596 Status
= NtPlugPlayControl(PlugPlayControlProperty
,
597 (PVOID
)&PlugPlayData
,
598 sizeof(PLUGPLAY_CONTROL_PROPERTY_DATA
));
599 if (NT_SUCCESS(Status
))
601 *Length
= PlugPlayData
.BufferSize
;
605 ret
= NtStatusToCrError(Status
);
609 DPRINT("PNP_GetDeviceRegProp() done (returns %lx)\n", ret
);
617 PNP_SetDeviceRegProp(handle_t BindingHandle
,
619 unsigned long Property
,
620 unsigned long DataType
,
622 unsigned long Length
,
625 CONFIGRET ret
= CR_SUCCESS
;
626 LPWSTR lpValueName
= NULL
;
629 DPRINT("PNP_SetDeviceRegProp() called\n");
631 DPRINT("DeviceId: %S\n", DeviceId
);
632 DPRINT("Property: %lu\n", Property
);
633 DPRINT("DataType: %lu\n", DataType
);
634 DPRINT("Length: %lu\n", Length
);
638 case CM_DRP_DEVICEDESC
:
639 lpValueName
= L
"DeviceDesc";
642 case CM_DRP_HARDWAREID
:
643 lpValueName
= L
"HardwareID";
646 case CM_DRP_COMPATIBLEIDS
:
647 lpValueName
= L
"CompatibleIDs";
651 lpValueName
= L
"Service";
655 lpValueName
= L
"Class";
658 case CM_DRP_CLASSGUID
:
659 lpValueName
= L
"ClassGUID";
663 lpValueName
= L
"Driver";
666 case CM_DRP_CONFIGFLAGS
:
667 lpValueName
= L
"ConfigFlags";
671 lpValueName
= L
"Mfg";
674 case CM_DRP_FRIENDLYNAME
:
675 lpValueName
= L
"FriendlyName";
678 case CM_DRP_LOCATION_INFORMATION
:
679 lpValueName
= L
"LocationInformation";
682 case CM_DRP_UPPERFILTERS
:
683 lpValueName
= L
"UpperFilters";
686 case CM_DRP_LOWERFILTERS
:
687 lpValueName
= L
"LowerFilters";
691 return CR_INVALID_PROPERTY
;
694 DPRINT("Value name: %S\n", lpValueName
);
696 if (RegOpenKeyExW(hEnumKey
,
701 return CR_INVALID_DEVNODE
;
705 if (RegDeleteValueW(hKey
,
707 ret
= CR_REGISTRY_ERROR
;
711 if (RegSetValueExW(hKey
,
717 ret
= CR_REGISTRY_ERROR
;
722 DPRINT("PNP_SetDeviceRegProp() done (returns %lx)\n", ret
);
730 PNP_GetClassInstance(handle_t BindingHandle
,
731 wchar_t *DeviceId
, /* in */
732 wchar_t *Buffer
, /* out */
733 unsigned long Length
)
735 CONFIGRET ret
= CR_SUCCESS
;
737 DPRINT("PNP_Get_Class_Instance() called\n");
739 DPRINT("PNP_Get_Class_Instance() done (returns %lx)\n", ret
);
747 PNP_CreateKey(handle_t BindingHandle
,
749 unsigned long samDesired
,
752 CONFIGRET ret
= CR_SUCCESS
;
754 DPRINT("PNP_CreateKey() called\n");
756 DPRINT("PNP_CreateKey() done (returns %lx)\n", ret
);
764 PNP_DeleteRegistryKey(handle_t BindingHandle
,
770 CONFIGRET ret
= CR_SUCCESS
;
772 DPRINT("PNP_DeleteRegistryKey() called\n");
774 DPRINT("PNP_DeleteRegistryKey() done (returns %lx)\n", ret
);
783 PNP_GetClassCount(handle_t BindingHandle
,
784 unsigned long *ClassCount
,
790 dwError
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
795 if (dwError
!= ERROR_SUCCESS
)
796 return CR_INVALID_DATA
;
798 dwError
= RegQueryInfoKeyW(hKey
,
811 if (dwError
!= ERROR_SUCCESS
)
812 return CR_INVALID_DATA
;
821 PNP_GetClassName(handle_t BindingHandle
,
824 unsigned long *Length
,
827 WCHAR szKeyName
[MAX_PATH
];
828 CONFIGRET ret
= CR_SUCCESS
;
832 DPRINT("PNP_GetClassName() called\n");
834 lstrcpyW(szKeyName
, L
"System\\CurrentControlSet\\Control\\Class");
835 lstrcatW(szKeyName
, L
"\\");
836 lstrcatW(szKeyName
, ClassGuid
);
838 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
843 return CR_REGISTRY_ERROR
;
845 ulSize
= *Length
* sizeof(WCHAR
);
846 if (RegQueryValueExW(hKey
,
854 ret
= CR_REGISTRY_ERROR
;
858 *Length
= ulSize
/ sizeof(WCHAR
);
863 DPRINT("PNP_GetClassName() done (returns %lx)\n", ret
);
871 PNP_DeleteClassKey(handle_t BindingHandle
,
875 CONFIGRET ret
= CR_SUCCESS
;
877 DPRINT("PNP_GetClassName(%S, %lx) called\n", ClassGuid
, Flags
);
879 if (Flags
& CM_DELETE_CLASS_SUBKEYS
)
881 if (RegDeleteTreeW(hClassKey
, ClassGuid
) != ERROR_SUCCESS
)
882 ret
= CR_REGISTRY_ERROR
;
886 if (RegDeleteKeyW(hClassKey
, ClassGuid
) != ERROR_SUCCESS
)
887 ret
= CR_REGISTRY_ERROR
;
890 DPRINT("PNP_DeleteClassKey() done (returns %lx)\n", ret
);
898 PNP_CreateDevInst(handle_t BindingHandle
,
899 wchar_t *DeviceId
, /* [in, out, string, size_is(Length)] */
900 wchar_t *ParentDeviceId
, /* [in, string] */
901 unsigned long Length
, /* [in] */
902 unsigned long Flags
) /* [in] */
904 CONFIGRET ret
= CR_CALL_NOT_IMPLEMENTED
;
906 DPRINT1("PNP_CreateDevInst() called\n");
908 DPRINT1("PNP_CreateDevInst() done (returns %lx)\n", ret
);
916 PNP_DeviceInstanceAction(handle_t BindingHandle
,
917 unsigned long MajorAction
,
918 unsigned long MinorAction
,
919 wchar_t *DeviceInstance1
,
920 wchar_t *DeviceInstance2
)
922 CONFIGRET ret
= CR_SUCCESS
;
924 DPRINT("PNP_DeviceInstanceAction() called\n");
929 DPRINT("Move device instance\n");
931 ret
= CR_CALL_NOT_IMPLEMENTED
;
935 DPRINT("Setup device instance\n");
937 ret
= CR_CALL_NOT_IMPLEMENTED
;
941 DPRINT("Enable device instance\n");
943 ret
= CR_CALL_NOT_IMPLEMENTED
;
947 DPRINT("Disable device instance\n");
949 ret
= CR_CALL_NOT_IMPLEMENTED
;
953 DPRINT("Reenumerate device instance\n");
955 ret
= CR_CALL_NOT_IMPLEMENTED
;
959 DPRINT1("Unknown function %lu\n", MajorAction
);
960 ret
= CR_CALL_NOT_IMPLEMENTED
;
963 DPRINT("PNP_DeviceInstanceAction() done (returns %lx)\n", ret
);
971 PNP_GetDeviceStatus(handle_t BindingHandle
,
972 wchar_t *DeviceInstance
,
973 unsigned long *pStatus
,
974 unsigned long *pProblem
,
977 PLUGPLAY_CONTROL_STATUS_DATA PlugPlayData
;
978 CONFIGRET ret
= CR_SUCCESS
;
981 DPRINT("PNP_GetDeviceStatus() called\n");
983 RtlInitUnicodeString(&PlugPlayData
.DeviceInstance
,
985 PlugPlayData
.Operation
= 0; /* Get status */
987 Status
= NtPlugPlayControl(PlugPlayControlDeviceStatus
,
988 (PVOID
)&PlugPlayData
,
989 sizeof(PLUGPLAY_CONTROL_STATUS_DATA
));
990 if (NT_SUCCESS(Status
))
992 *pStatus
= PlugPlayData
.DeviceStatus
;
993 *pProblem
= PlugPlayData
.DeviceProblem
;
997 ret
= NtStatusToCrError(Status
);
1000 DPRINT("PNP_GetDeviceStatus() done (returns %lx)\n", ret
);
1008 PNP_SetDeviceProblem(handle_t BindingHandle
,
1009 wchar_t *DeviceInstance
,
1010 unsigned long Problem
,
1013 CONFIGRET ret
= CR_SUCCESS
;
1015 DPRINT1("PNP_SetDeviceProblem() called\n");
1019 DPRINT1("PNP_SetDeviceProblem() done (returns %lx)\n", ret
);
1027 PNP_UninstallDevInst(handle_t BindingHandle
,
1028 wchar_t *DeviceInstance
,
1031 CONFIGRET ret
= CR_SUCCESS
;
1033 DPRINT1("PNP_UninstallDevInst() called\n");
1037 DPRINT1("PNP_UninstallDevInst() done (returns %lx)\n", ret
);
1045 PNP_IsDockStationPresent(handle_t BindingHandle
,
1046 unsigned long *Present
)
1052 CONFIGRET ret
= CR_SUCCESS
;
1054 DPRINT1("PNP_IsDockStationPresent() called\n");
1058 if (RegOpenKeyExW(HKEY_CURRENT_CONFIG
,
1062 &hKey
) != ERROR_SUCCESS
)
1063 return CR_REGISTRY_ERROR
;
1065 dwSize
= sizeof(DWORD
);
1066 if (RegQueryValueExW(hKey
,
1071 &dwSize
) != ERROR_SUCCESS
)
1072 ret
= CR_REGISTRY_ERROR
;
1076 if (ret
== CR_SUCCESS
)
1078 if (dwType
!= REG_DWORD
|| dwSize
!= sizeof(DWORD
))
1080 ret
= CR_REGISTRY_ERROR
;
1082 else if (dwValue
!= 0)
1088 DPRINT1("PNP_IsDockStationPresent() done (returns %lx)\n", ret
);
1096 PNP_RequestEjectPC(handle_t BindingHandle
)
1098 CONFIGRET ret
= CR_SUCCESS
;
1100 DPRINT1("PNP_RequestEjectPC() called\n");
1102 ret
= CR_FAILURE
; /* FIXME */
1104 DPRINT1("PNP_RequestEjectPC() done (returns %lx)\n", ret
);
1112 PNP_RunDetection(handle_t BindingHandle
,
1113 unsigned long Flags
)
1115 DPRINT("PNP_RunDetection() called\n");
1116 return CR_CALL_NOT_IMPLEMENTED
;
1120 typedef BOOL (WINAPI
*PDEV_INSTALL_W
)(HWND
, HINSTANCE
, LPCWSTR
, INT
);
1123 InstallDevice(PCWSTR DeviceInstance
, BOOL SetupIsActive
)
1125 PLUGPLAY_CONTROL_STATUS_DATA PlugPlayData
;
1126 HMODULE hNewDev
= NULL
;
1127 PDEV_INSTALL_W DevInstallW
;
1129 BOOL DeviceInstalled
= FALSE
;
1131 RtlInitUnicodeString(&PlugPlayData
.DeviceInstance
,
1133 PlugPlayData
.Operation
= 0; /* Get status */
1135 /* Get device status */
1136 Status
= NtPlugPlayControl(PlugPlayControlDeviceStatus
,
1137 (PVOID
)&PlugPlayData
,
1138 sizeof(PLUGPLAY_CONTROL_STATUS_DATA
));
1139 if (!NT_SUCCESS(Status
))
1142 if (PlugPlayData
.DeviceStatus
& DNF_STARTED
|| PlugPlayData
.DeviceStatus
& DNF_START_FAILED
)
1143 /* Device is already started, or disabled due to some problem. Don't install it */
1146 /* Install device */
1147 SetEnvironmentVariable(L
"USERPROFILE", L
"."); /* FIXME: why is it needed? */
1149 hNewDev
= LoadLibraryW(L
"newdev.dll");
1153 DevInstallW
= (PDEV_INSTALL_W
)GetProcAddress(hNewDev
, (LPCSTR
)"DevInstallW");
1157 if (!DevInstallW(NULL
, NULL
, DeviceInstance
, SetupIsActive
? SW_HIDE
: SW_SHOWNOACTIVATE
))
1160 DeviceInstalled
= TRUE
;
1163 if (hNewDev
!= NULL
)
1164 FreeLibrary(hNewDev
);
1166 return DeviceInstalled
;
1173 HKEY hKey
= INVALID_HANDLE_VALUE
;
1174 DWORD regType
, active
, size
;
1178 rc
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, L
"SYSTEM\\Setup", 0, KEY_QUERY_VALUE
, &hKey
);
1179 if (rc
!= ERROR_SUCCESS
)
1182 size
= sizeof(DWORD
);
1183 rc
= RegQueryValueExW(hKey
, L
"SystemSetupInProgress", NULL
, ®Type
, (LPBYTE
)&active
, &size
);
1184 if (rc
!= ERROR_SUCCESS
)
1186 if (regType
!= REG_DWORD
|| size
!= sizeof(DWORD
))
1189 ret
= (active
!= 0);
1192 if (hKey
!= INVALID_HANDLE_VALUE
)
1195 DPRINT("System setup in progress? %S\n", ret
? L
"YES" : L
"NO");
1202 PnpEventThread(LPVOID lpParameter
)
1204 PPLUGPLAY_EVENT_BLOCK PnpEvent
;
1207 RPC_STATUS RpcStatus
;
1210 PnpEventSize
= 0x1000;
1211 PnpEvent
= HeapAlloc(GetProcessHeap(), 0, PnpEventSize
);
1212 if (PnpEvent
== NULL
)
1213 return ERROR_OUTOFMEMORY
;
1215 setupActive
= SetupIsActive();
1219 DPRINT("Calling NtGetPlugPlayEvent()\n");
1221 /* Wait for the next pnp event */
1222 Status
= NtGetPlugPlayEvent(0, 0, PnpEvent
, PnpEventSize
);
1224 /* Resize the buffer for the PnP event if it's too small. */
1225 if (Status
== STATUS_BUFFER_TOO_SMALL
)
1227 PnpEventSize
+= 0x400;
1228 PnpEvent
= HeapReAlloc(GetProcessHeap(), 0, PnpEvent
, PnpEventSize
);
1229 if (PnpEvent
== NULL
)
1230 return ERROR_OUTOFMEMORY
;
1234 if (!NT_SUCCESS(Status
))
1236 DPRINT("NtPlugPlayEvent() failed (Status %lx)\n", Status
);
1240 DPRINT("Received PnP Event\n");
1241 if (UuidEqual(&PnpEvent
->EventGuid
, (UUID
*)&GUID_DEVICE_ARRIVAL
, &RpcStatus
))
1243 DPRINT("Device arrival event: %S\n", PnpEvent
->TargetDevice
.DeviceIds
);
1244 InstallDevice(PnpEvent
->TargetDevice
.DeviceIds
, setupActive
);
1248 DPRINT1("Unknown event\n");
1251 /* FIXME: Process the pnp event */
1253 /* Dequeue the current pnp event and signal the next one */
1254 NtPlugPlayControl(PlugPlayControlUserResponse
, NULL
, 0);
1257 HeapFree(GetProcessHeap(), 0, PnpEvent
);
1259 return ERROR_SUCCESS
;
1263 static VOID CALLBACK
1264 ServiceMain(DWORD argc
, LPTSTR
*argv
)
1269 DPRINT("ServiceMain() called\n");
1271 hThread
= CreateThread(NULL
,
1277 if (hThread
!= NULL
)
1278 CloseHandle(hThread
);
1280 hThread
= CreateThread(NULL
,
1286 if (hThread
!= NULL
)
1287 CloseHandle(hThread
);
1289 DPRINT("ServiceMain() done\n");
1294 main(int argc
, char *argv
[])
1298 DPRINT("Umpnpmgr: main() started\n");
1300 hInstallEvent
= CreateEvent(NULL
, TRUE
, FALSE
, NULL
);
1301 if (hInstallEvent
== NULL
)
1303 dwError
= GetLastError();
1304 DPRINT1("Could not create the Install Event! (Error %lu)\n", dwError
);
1308 dwError
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
1309 L
"System\\CurrentControlSet\\Enum",
1313 if (dwError
!= ERROR_SUCCESS
)
1315 DPRINT1("Could not open the Enum Key! (Error %lu)\n", dwError
);
1319 dwError
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
1320 L
"System\\CurrentControlSet\\Control\\Class",
1324 if (dwError
!= ERROR_SUCCESS
)
1326 DPRINT1("Could not open the Class Key! (Error %lu)\n", dwError
);
1330 StartServiceCtrlDispatcher(ServiceTable
);
1332 DPRINT("Umpnpmgr: main() done\n");