2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS New devices installation
4 * FILE: lib/newdev/newdev.c
5 * PURPOSE: New devices installation
7 * PROGRAMMERS: Hervé Poussineau (hpoussin@reactos.org)
8 * PROGRAMMERS: Christoph von Wittich (Christoph@ActiveVB.de)
16 static BOOL
SearchDriver ( PDEVINSTDATA DevInstData
, LPCTSTR Path
);
17 static BOOL
InstallDriver ( PDEVINSTDATA DevInstData
);
18 static DWORD WINAPI
FindDriverProc( LPVOID lpParam
);
19 static BOOL
FindDriver ( PDEVINSTDATA DevInstData
);
21 static DEVINSTDATA DevInstData
;
22 HINSTANCE hDllInstance
;
26 CanDisableDevice(IN DEVINST DevInst
,
31 ULONG Status
, ProblemNumber
;
34 cr
= CM_Get_DevNode_Status_Ex(&Status
,
41 *CanDisable
= ((Status
& DN_DISABLEABLE
) != 0);
50 IsDeviceEnabled(IN DEVINST DevInst
,
55 ULONG Status
, ProblemNumber
;
58 cr
= CM_Get_DevNode_Status_Ex(&Status
,
65 *IsEnabled
= ((Status
& DN_STARTED
) != 0);
74 EnableDevice(IN HDEVINFO DeviceInfoSet
,
75 IN PSP_DEVINFO_DATA DevInfoData OPTIONAL
,
77 IN DWORD HardwareProfile OPTIONAL
,
78 OUT BOOL
*bNeedReboot OPTIONAL
)
80 SP_PROPCHANGE_PARAMS pcp
;
81 SP_DEVINSTALL_PARAMS dp
;
85 pcp
.ClassInstallHeader
.cbSize
= sizeof(SP_CLASSINSTALL_HEADER
);
86 pcp
.ClassInstallHeader
.InstallFunction
= DIF_PROPERTYCHANGE
;
87 pcp
.HwProfile
= HardwareProfile
;
91 /* try to enable the device on the global profile */
92 pcp
.StateChange
= DICS_ENABLE
;
93 pcp
.Scope
= DICS_FLAG_GLOBAL
;
96 LastErr
= GetLastError();
97 if (SetupDiSetClassInstallParams(DeviceInfoSet
,
99 &pcp
.ClassInstallHeader
,
100 sizeof(SP_PROPCHANGE_PARAMS
)))
102 SetupDiCallClassInstaller(DIF_PROPERTYCHANGE
,
106 SetLastError(LastErr
);
109 /* try config-specific */
110 pcp
.StateChange
= (bEnable
? DICS_ENABLE
: DICS_DISABLE
);
111 pcp
.Scope
= DICS_FLAG_CONFIGSPECIFIC
;
113 if (SetupDiSetClassInstallParams(DeviceInfoSet
,
115 &pcp
.ClassInstallHeader
,
116 sizeof(SP_PROPCHANGE_PARAMS
)) &&
117 SetupDiCallClassInstaller(DIF_PROPERTYCHANGE
,
121 dp
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS
);
122 if (SetupDiGetDeviceInstallParams(DeviceInfoSet
,
126 if (bNeedReboot
!= NULL
)
128 *bNeedReboot
= ((dp
.Flags
& (DI_NEEDRESTART
| DI_NEEDREBOOT
)) != 0);
141 UpdateDriverForPlugAndPlayDevicesW(
143 IN LPCWSTR HardwareId
,
144 IN LPCWSTR FullInfPath
,
145 IN DWORD InstallFlags
,
146 OUT PBOOL bRebootRequired OPTIONAL
)
149 SetLastError(ERROR_GEN_FAILURE
);
157 UpdateDriverForPlugAndPlayDevicesA(
159 IN LPCSTR HardwareId
,
160 IN LPCSTR FullInfPath
,
161 IN DWORD InstallFlags
,
162 OUT PBOOL bRebootRequired OPTIONAL
)
165 LPWSTR HardwareIdW
= NULL
;
166 LPWSTR FullInfPathW
= NULL
;
168 int len
= MultiByteToWideChar(CP_ACP
, 0, HardwareId
, -1, NULL
, 0);
169 HardwareIdW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
172 SetLastError(ERROR_GEN_FAILURE
);
175 MultiByteToWideChar(CP_ACP
, 0, HardwareId
, -1, HardwareIdW
, len
);
177 len
= MultiByteToWideChar(CP_ACP
, 0, FullInfPath
, -1, NULL
, 0);
178 FullInfPathW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
181 HeapFree(GetProcessHeap(), 0, HardwareIdW
);
182 SetLastError(ERROR_GEN_FAILURE
);
185 MultiByteToWideChar(CP_ACP
, 0, FullInfPath
, -1, FullInfPathW
, len
);
187 Result
= UpdateDriverForPlugAndPlayDevicesW(hwndParent
,
193 HeapFree(GetProcessHeap(), 0, HardwareIdW
);
194 HeapFree(GetProcessHeap(), 0, FullInfPathW
);
201 CreateTitleFont(VOID
)
203 NONCLIENTMETRICS ncm
;
209 ncm
.cbSize
= sizeof(NONCLIENTMETRICS
);
210 SystemParametersInfo(SPI_GETNONCLIENTMETRICS
, 0, &ncm
, 0);
212 LogFont
= ncm
.lfMessageFont
;
213 LogFont
.lfWeight
= FW_BOLD
;
214 _tcscpy(LogFont
.lfFaceName
, _T("MS Shell Dlg"));
218 LogFont
.lfHeight
= 0 - GetDeviceCaps (hdc
, LOGPIXELSY
) * FontSize
/ 72;
219 hFont
= CreateFontIndirect(&LogFont
);
220 ReleaseDC(NULL
, hdc
);
226 CenterWindow(HWND hWnd
)
232 hWndParent
= GetParent(hWnd
);
233 if (hWndParent
== NULL
)
234 hWndParent
= GetDesktopWindow();
236 GetWindowRect(hWndParent
, &rcParent
);
237 GetWindowRect(hWnd
, &rcWindow
);
241 ((rcParent
.right
- rcParent
.left
) - (rcWindow
.right
- rcWindow
.left
)) / 2,
242 ((rcParent
.bottom
- rcParent
.top
) - (rcWindow
.bottom
- rcWindow
.top
)) / 2,
248 static INT_PTR CALLBACK
256 PDEVINSTDATA DevInstData
;
258 /* Retrieve pointer to the global setup data */
259 DevInstData
= (PDEVINSTDATA
)GetWindowLongPtr (hwndDlg
, GWL_USERDATA
);
268 /* Get pointer to the global setup data */
269 DevInstData
= (PDEVINSTDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
270 SetWindowLongPtr(hwndDlg
, GWL_USERDATA
, (DWORD_PTR
)DevInstData
);
272 hwndControl
= GetParent(hwndDlg
);
274 /* Center the wizard window */
275 CenterWindow (hwndControl
);
277 /* Hide the system menu */
278 dwStyle
= GetWindowLong(hwndControl
, GWL_STYLE
);
279 SetWindowLong(hwndControl
, GWL_STYLE
, dwStyle
& ~WS_SYSMENU
);
282 SendDlgItemMessage(hwndDlg
,
285 (WPARAM
)DevInstData
->hTitleFont
,
288 SendDlgItemMessage(hwndDlg
,
292 (LPARAM
) DevInstData
->buffer
);
294 SendDlgItemMessage(hwndDlg
,
307 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
312 /* Enable the Next button */
313 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_NEXT
);
317 /* Handle a Next button click, if necessary */
319 if (SendDlgItemMessage(hwndDlg
, IDC_RADIO_AUTO
, BM_GETCHECK
, (WPARAM
) 0, (LPARAM
) 0) == BST_CHECKED
)
320 PropSheet_SetCurSel(GetParent(hwndDlg
), 0, IDD_SEARCHDRV
);
337 static INT_PTR CALLBACK
345 PDEVINSTDATA DevInstData
;
347 /* Retrieve pointer to the global setup data */
348 DevInstData
= (PDEVINSTDATA
)GetWindowLongPtr (hwndDlg
, GWL_USERDATA
);
357 /* Get pointer to the global setup data */
358 DevInstData
= (PDEVINSTDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
359 SetWindowLongPtr(hwndDlg
, GWL_USERDATA
, (DWORD_PTR
)DevInstData
);
361 hwndControl
= GetParent(hwndDlg
);
363 /* Center the wizard window */
364 CenterWindow (hwndControl
);
366 /* Hide the system menu */
367 dwStyle
= GetWindowLong(hwndControl
, GWL_STYLE
);
368 SetWindowLong(hwndControl
, GWL_STYLE
, dwStyle
& ~WS_SYSMENU
);
370 SendDlgItemMessage(hwndDlg
,
371 IDC_RADIO_SEARCHHERE
,
382 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
387 /* Enable the Next and Back buttons */
388 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_NEXT
| PSWIZB_BACK
);
392 /* Handle a Next button click, if necessary */
393 PropSheet_SetCurSel(GetParent(hwndDlg
), 0, 4);
409 static INT_PTR CALLBACK
417 PDEVINSTDATA DevInstData
;
420 /* Retrieve pointer to the global setup data */
421 DevInstData
= (PDEVINSTDATA
)GetWindowLongPtr (hwndDlg
, GWL_USERDATA
);
430 /* Get pointer to the global setup data */
431 DevInstData
= (PDEVINSTDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
432 SetWindowLongPtr(hwndDlg
, GWL_USERDATA
, (DWORD_PTR
)DevInstData
);
434 DevInstData
->hDialog
= hwndDlg
;
435 hwndControl
= GetParent(hwndDlg
);
437 /* Center the wizard window */
438 CenterWindow (hwndControl
);
440 SendDlgItemMessage(hwndDlg
,
444 (LPARAM
) DevInstData
->buffer
);
446 /* Hide the system menu */
447 dwStyle
= GetWindowLong(hwndControl
, GWL_STYLE
);
448 SetWindowLong(hwndControl
, GWL_STYLE
, dwStyle
& ~WS_SYSMENU
);
452 case WM_SEARCH_FINISHED
:
454 CloseHandle(hThread
);
457 PropSheet_SetCurSel(GetParent(hwndDlg
), 0, IDD_NODRIVER
);
459 PropSheet_SetCurSel(GetParent(hwndDlg
), 0, IDD_FINISHPAGE
);
464 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
469 PropSheet_SetWizButtons(GetParent(hwndDlg
), !PSWIZB_NEXT
| !PSWIZB_BACK
);
470 hThread
= CreateThread( NULL
, 0, FindDriverProc
, DevInstData
, 0, &dwThreadId
);
476 SetWindowLong ( hwndDlg
, DWL_MSGRESULT
, TRUE
);
481 /* Handle a Next button click, if necessary */
501 TCHAR drive
[] = {'?',':',0};
504 PDEVINSTDATA DevInstData
;
508 DevInstData
= (PDEVINSTDATA
)lpParam
;
510 dwDrives
= GetLogicalDrives();
511 for (drive
[0] = 'A'; drive
[0] <= 'Z'; drive
[0]++)
515 nType
= GetDriveType( drive
);
516 if ((nType
== DRIVE_CDROM
))
517 //if ((nType == DRIVE_CDROM) || (nType == DRIVE_FIXED))
519 /* search for inf file */
520 if (SearchDriver ( DevInstData
, drive
))
522 /* if we found a valid driver inf... */
523 if (FindDriver ( DevInstData
))
525 InstallDriver ( DevInstData
);
526 PostMessage(DevInstData
->hDialog
, WM_SEARCH_FINISHED
, 1, 0);
535 /* update device configuration */
536 if(SetupDiGetDeviceRegistryProperty(DevInstData
->hDevInfo
,
537 &DevInstData
->devInfoData
,
540 (BYTE
*)&config_flags
,
541 sizeof(config_flags
),
544 config_flags
|= CONFIGFLAG_FAILEDINSTALL
;
545 SetupDiSetDeviceRegistryProperty(
546 DevInstData
->hDevInfo
,
547 &DevInstData
->devInfoData
,
552 PostMessage(DevInstData
->hDialog
, WM_SEARCH_FINISHED
, 0, 0);
556 static INT_PTR CALLBACK
564 PDEVINSTDATA DevInstData
;
566 /* Retrieve pointer to the global setup data */
567 DevInstData
= (PDEVINSTDATA
)GetWindowLongPtr (hwndDlg
, GWL_USERDATA
);
575 /* Get pointer to the global setup data */
576 DevInstData
= (PDEVINSTDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
577 SetWindowLongPtr(hwndDlg
, GWL_USERDATA
, (DWORD_PTR
)DevInstData
);
579 hwndControl
= GetDlgItem(GetParent(hwndDlg
), IDCANCEL
);
580 ShowWindow (hwndControl
, SW_HIDE
);
581 EnableWindow (hwndControl
, FALSE
);
583 SendDlgItemMessage(hwndDlg
,
587 (LPARAM
) DevInstData
->drvInfoData
.Description
);
590 SendDlgItemMessage(hwndDlg
,
593 (WPARAM
)DevInstData
->hTitleFont
,
600 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
605 /* Enable the correct buttons on for the active page */
606 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_FINISH
);
610 /* Handle a Back button click, if necessary */
614 /* Handle a Finish button click, if necessary */
630 static INT_PTR CALLBACK
638 PDEVINSTDATA DevInstData
;
640 /* Get pointer to the global setup data */
641 DevInstData
= (PDEVINSTDATA
)GetWindowLongPtr (hwndDlg
, GWL_USERDATA
);
648 BOOL DisableableDevice
= FALSE
;
650 DevInstData
= (PDEVINSTDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
651 SetWindowLongPtr(hwndDlg
, GWL_USERDATA
, (DWORD_PTR
)DevInstData
);
653 hwndControl
= GetDlgItem(GetParent(hwndDlg
), IDCANCEL
);
654 ShowWindow (hwndControl
, SW_HIDE
);
655 EnableWindow (hwndControl
, FALSE
);
658 SendDlgItemMessage(hwndDlg
,
661 (WPARAM
)DevInstData
->hTitleFont
,
664 /* disable the "do not show this dialog anymore" checkbox
665 if the device cannot be disabled */
666 CanDisableDevice(DevInstData
->devInfoData
.DevInst
,
669 EnableWindow(GetDlgItem(hwndDlg
,
677 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
682 /* Enable the correct buttons on for the active page */
683 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_FINISH
);
687 PropSheet_SetCurSel(GetParent(hwndDlg
), 0, IDD_WELCOMEPAGE
);
688 /* Handle a Back button click, if necessary */
693 BOOL DisableableDevice
= FALSE
;
694 BOOL IsEnabled
= FALSE
;
696 if (CanDisableDevice(DevInstData
->devInfoData
.DevInst
,
698 &DisableableDevice
) &&
700 IsDeviceEnabled(DevInstData
->devInfoData
.DevInst
,
704 SendDlgItemMessage(hwndDlg
, IDC_DONOTSHOWDLG
, BM_GETCHECK
, (WPARAM
) 0, (LPARAM
) 0) == BST_CHECKED
)
706 /* disable the device */
707 EnableDevice(DevInstData
->hDevInfo
,
708 &DevInstData
->devInfoData
,
732 IN PDEVINSTDATA DevInstData
)
737 ret
= SetupDiBuildDriverInfoList(DevInstData
->hDevInfo
, &DevInstData
->devInfoData
, SPDIT_COMPATDRIVER
);
740 DPRINT("SetupDiBuildDriverInfoList() failed with error 0x%lx\n", GetLastError());
744 DevInstData
->drvInfoData
.cbSize
= sizeof(SP_DRVINFO_DATA
);
745 ret
= SetupDiEnumDriverInfo(
746 DevInstData
->hDevInfo
,
747 &DevInstData
->devInfoData
,
750 &DevInstData
->drvInfoData
);
753 if (GetLastError() == ERROR_NO_MORE_ITEMS
)
755 DPRINT("SetupDiEnumDriverInfo() failed with error 0x%lx\n", GetLastError());
758 DPRINT("Installing driver %S: %S\n", DevInstData
->drvInfoData
.MfgName
, DevInstData
->drvInfoData
.Description
);
765 IsDots(IN LPCTSTR str
)
767 if(_tcscmp(str
, _T(".")) && _tcscmp(str
, _T(".."))) return FALSE
;
772 GetFileExt(IN LPTSTR FileName
)
777 int i
= _tcsclen(FileName
);
778 while ((i
>= 0) && (FileName
[i
] != _T('.')))
781 FileName
= _tcslwr(FileName
);
791 IN PDEVINSTDATA DevInstData
,
795 SP_DEVINSTALL_PARAMS DevInstallParams
;
796 TCHAR DirPath
[MAX_PATH
];
797 TCHAR FileName
[MAX_PATH
];
798 TCHAR FullPath
[MAX_PATH
];
799 TCHAR LastDirPath
[MAX_PATH
] = _T("");
800 TCHAR PathWithPattern
[MAX_PATH
];
805 _tcscpy(DirPath
, Path
);
807 if (DirPath
[_tcsclen(DirPath
) - 1] != '\\')
808 _tcscat(DirPath
, _T("\\"));
810 _tcscpy(PathWithPattern
, DirPath
);
811 _tcscat(PathWithPattern
, _T("\\*"));
813 for (hFindFile
= FindFirstFile(PathWithPattern
, &wfd
); ((hFindFile
!= INVALID_HANDLE_VALUE
) && ok
); ok
= FindNextFile(hFindFile
, &wfd
))
816 _tcscpy(FileName
, wfd
.cFileName
);
817 if (IsDots(FileName
)) continue;
819 if((wfd
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
))
821 _tcscpy(FullPath
, DirPath
);
822 _tcscat(FullPath
, FileName
);
823 if(SearchDriver(DevInstData
, FullPath
))
828 LPCTSTR pszExtension
= GetFileExt(FileName
);
830 if ((_tcscmp(pszExtension
, _T(".inf")) == 0) && (_tcscmp(LastDirPath
, DirPath
) != 0))
832 _tcscpy(LastDirPath
, DirPath
);
833 ZeroMemory (&DevInstallParams
, sizeof(SP_DEVINSTALL_PARAMS
));
834 DevInstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS
);
836 ret
= SetupDiGetDeviceInstallParams(
837 DevInstData
->hDevInfo
,
838 &DevInstData
->devInfoData
,
841 if (_tcsclen(DirPath
) <= MAX_PATH
)
843 memcpy(DevInstallParams
.DriverPath
, DirPath
, (_tcsclen(DirPath
) + 1) * sizeof(TCHAR
));
846 ret
= SetupDiSetDeviceInstallParams(
847 DevInstData
->hDevInfo
,
848 &DevInstData
->devInfoData
,
851 if ( FindDriver ( DevInstData
) )
853 if (hFindFile
!= INVALID_HANDLE_VALUE
)
854 FindClose(hFindFile
);
862 if (hFindFile
!= INVALID_HANDLE_VALUE
)
863 FindClose(hFindFile
);
870 IN PDEVINSTDATA DevInstData
)
875 ret
= SetupDiCallClassInstaller(
876 DIF_SELECTBESTCOMPATDRV
,
877 DevInstData
->hDevInfo
,
878 &DevInstData
->devInfoData
);
881 DPRINT("SetupDiCallClassInstaller(DIF_SELECTBESTCOMPATDRV) failed with error 0x%lx\n", GetLastError());
885 ret
= SetupDiCallClassInstaller(
887 DevInstData
->hDevInfo
,
888 &DevInstData
->devInfoData
);
891 DPRINT("SetupDiCallClassInstaller(DIF_ALLOW_INSTALL) failed with error 0x%lx\n", GetLastError());
895 ret
= SetupDiCallClassInstaller(
896 DIF_NEWDEVICEWIZARD_PREANALYZE
,
897 DevInstData
->hDevInfo
,
898 &DevInstData
->devInfoData
);
901 DPRINT("SetupDiCallClassInstaller(DIF_NEWDEVICEWIZARD_PREANALYZE) failed with error 0x%lx\n", GetLastError());
905 ret
= SetupDiCallClassInstaller(
906 DIF_NEWDEVICEWIZARD_POSTANALYZE
,
907 DevInstData
->hDevInfo
,
908 &DevInstData
->devInfoData
);
911 DPRINT("SetupDiCallClassInstaller(DIF_NEWDEVICEWIZARD_POSTANALYZE) failed with error 0x%lx\n", GetLastError());
915 ret
= SetupDiCallClassInstaller(
916 DIF_INSTALLDEVICEFILES
,
917 DevInstData
->hDevInfo
,
918 &DevInstData
->devInfoData
);
921 DPRINT("SetupDiCallClassInstaller(DIF_INSTALLDEVICEFILES) failed with error 0x%lx\n", GetLastError());
925 ret
= SetupDiCallClassInstaller(
926 DIF_REGISTER_COINSTALLERS
,
927 DevInstData
->hDevInfo
,
928 &DevInstData
->devInfoData
);
931 DPRINT("SetupDiCallClassInstaller(DIF_REGISTER_COINSTALLERS) failed with error 0x%lx\n", GetLastError());
935 ret
= SetupDiCallClassInstaller(
936 DIF_INSTALLINTERFACES
,
937 DevInstData
->hDevInfo
,
938 &DevInstData
->devInfoData
);
941 DPRINT("SetupDiCallClassInstaller(DIF_INSTALLINTERFACES) failed with error 0x%lx\n", GetLastError());
945 ret
= SetupDiCallClassInstaller(
947 DevInstData
->hDevInfo
,
948 &DevInstData
->devInfoData
);
951 DPRINT("SetupDiCallClassInstaller(DIF_INSTALLDEVICE) failed with error 0x%lx\n", GetLastError());
955 ret
= SetupDiCallClassInstaller(
956 DIF_NEWDEVICEWIZARD_FINISHINSTALL
,
957 DevInstData
->hDevInfo
,
958 &DevInstData
->devInfoData
);
961 DPRINT("SetupDiCallClassInstaller(DIF_NEWDEVICEWIZARD_FINISHINSTALL) failed with error 0x%lx\n", GetLastError());
965 ret
= SetupDiCallClassInstaller(
966 DIF_DESTROYPRIVATEDATA
,
967 DevInstData
->hDevInfo
,
968 &DevInstData
->devInfoData
);
971 DPRINT("SetupDiCallClassInstaller(DIF_DESTROYPRIVATEDATA) failed with error 0x%lx\n", GetLastError());
983 if (DevInstData
.devInfoData
.cbSize
!= 0)
985 if (!SetupDiDestroyDriverInfoList(DevInstData
.hDevInfo
, &DevInstData
.devInfoData
, SPDIT_COMPATDRIVER
))
986 DPRINT("SetupDiDestroyDriverInfoList() failed with error 0x%lx\n", GetLastError());
989 if (DevInstData
.hDevInfo
!= INVALID_HANDLE_VALUE
)
991 if (!SetupDiDestroyDeviceInfoList(DevInstData
.hDevInfo
))
992 DPRINT("SetupDiDestroyDeviceInfoList() failed with error 0x%lx\n", GetLastError());
995 if (DevInstData
.buffer
)
996 HeapFree(GetProcessHeap(), 0, DevInstData
.buffer
);
1003 IN HINSTANCE hInstance
,
1004 IN LPCWSTR InstanceId
,
1008 PROPSHEETHEADER psh
;
1009 HPROPSHEETPAGE ahpsp
[5];
1015 /* FIXME: Nov 2005. umpnpmgr.exe is directly calling DevInstallW in
1016 * SYSTEM context, which is not member of the Administrators group.
1017 * So, just ignore the test at the moment... */
1018 //if (!IsUserAdmin())
1020 // /* XP kills the process... */
1021 // ExitProcess(ERROR_ACCESS_DENIED);
1024 /* Clear devinst data */
1025 ZeroMemory(&DevInstData
, sizeof(DEVINSTDATA
));
1026 DevInstData
.devInfoData
.cbSize
= 0; /* Tell if the devInfoData is valid */
1029 DevInstData
.hDevInfo
= SetupDiCreateDeviceInfoListExW(NULL
, NULL
, NULL
, NULL
);
1030 if (DevInstData
.hDevInfo
== INVALID_HANDLE_VALUE
)
1032 DPRINT("SetupDiCreateDeviceInfoListExW() failed with error 0x%lx\n", GetLastError());
1037 DevInstData
.devInfoData
.cbSize
= sizeof(SP_DEVINFO_DATA
);
1038 ret
= SetupDiOpenDeviceInfoW(
1039 DevInstData
.hDevInfo
,
1043 &DevInstData
.devInfoData
);
1046 DPRINT("SetupDiOpenDeviceInfoW() failed with error 0x%lx (InstanceId %S)\n", GetLastError(), InstanceId
);
1047 DevInstData
.devInfoData
.cbSize
= 0;
1052 SetLastError(ERROR_GEN_FAILURE
);
1053 ret
= SetupDiGetDeviceRegistryProperty(
1054 DevInstData
.hDevInfo
,
1055 &DevInstData
.devInfoData
,
1057 &DevInstData
.regDataType
,
1059 &DevInstData
.requiredSize
);
1061 if (!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
&& DevInstData
.regDataType
== REG_SZ
)
1063 DevInstData
.buffer
= HeapAlloc(GetProcessHeap(), 0, DevInstData
.requiredSize
);
1064 if (!DevInstData
.buffer
)
1066 DPRINT("HeapAlloc() failed\n");
1067 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1071 ret
= SetupDiGetDeviceRegistryProperty(
1072 DevInstData
.hDevInfo
,
1073 &DevInstData
.devInfoData
,
1075 &DevInstData
.regDataType
,
1076 DevInstData
.buffer
, DevInstData
.requiredSize
,
1077 &DevInstData
.requiredSize
);
1082 DPRINT("SetupDiGetDeviceRegistryProperty() failed with error 0x%lx (InstanceId %S)\n", GetLastError(), InstanceId
);
1087 if(SetupDiGetDeviceRegistryProperty(DevInstData
.hDevInfo
,
1088 &DevInstData
.devInfoData
,
1091 (BYTE
*)&config_flags
,
1092 sizeof(config_flags
),
1095 if (config_flags
& CONFIGFLAG_FAILEDINSTALL
)
1104 swprintf(buf, _T("%ld"), GetLastError());
1105 MessageBox(0,buf,buf,0);
1109 DPRINT("Installing %S (%S)\n", DevInstData
.buffer
, InstanceId
);
1111 if ((!FindDriver(&DevInstData
)) && (Show
!= SW_HIDE
))
1114 /* Create the Welcome page */
1115 ZeroMemory (&psp
, sizeof(PROPSHEETPAGE
));
1116 psp
.dwSize
= sizeof(PROPSHEETPAGE
);
1117 psp
.dwFlags
= PSP_DEFAULT
| PSP_HIDEHEADER
;
1118 psp
.hInstance
= hDllInstance
;
1119 psp
.lParam
= (LPARAM
)&DevInstData
;
1120 psp
.pfnDlgProc
= WelcomeDlgProc
;
1121 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_WELCOMEPAGE
);
1122 ahpsp
[IDD_WELCOMEPAGE
] = CreatePropertySheetPage(&psp
);
1124 /* Create the Select Source page */
1125 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
1126 psp
.pfnDlgProc
= CHSourceDlgProc
;
1127 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_CHSOURCE
);
1128 ahpsp
[IDD_CHSOURCE
] = CreatePropertySheetPage(&psp
);
1130 /* Create the Search driver page */
1131 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
1132 psp
.pfnDlgProc
= SearchDrvDlgProc
;
1133 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_SEARCHDRV
);
1134 ahpsp
[IDD_SEARCHDRV
] = CreatePropertySheetPage(&psp
);
1136 /* Create the Finish page */
1137 psp
.dwFlags
= PSP_DEFAULT
| PSP_HIDEHEADER
;
1138 psp
.pfnDlgProc
= FinishDlgProc
;
1139 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_FINISHPAGE
);
1140 ahpsp
[IDD_FINISHPAGE
] = CreatePropertySheetPage(&psp
);
1142 /* Create the Install failed page */
1143 psp
.dwFlags
= PSP_DEFAULT
| PSP_HIDEHEADER
;
1144 psp
.pfnDlgProc
= InstFailDlgProc
;
1145 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_NODRIVER
);
1146 ahpsp
[IDD_NODRIVER
] = CreatePropertySheetPage(&psp
);
1148 /* Create the property sheet */
1149 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
1150 psh
.dwFlags
= PSH_WIZARD97
| PSH_WATERMARK
| PSH_HEADER
;
1151 psh
.hInstance
= hDllInstance
;
1152 psh
.hwndParent
= NULL
;
1156 psh
.pszbmWatermark
= MAKEINTRESOURCE(IDB_WATERMARK
);
1157 psh
.pszbmHeader
= MAKEINTRESOURCE(IDB_HEADER
);
1159 /* Create title font */
1160 DevInstData
.hTitleFont
= CreateTitleFont();
1162 /* Display the wizard */
1163 PropertySheet(&psh
);
1165 DeleteObject(DevInstData
.hTitleFont
);
1170 InstallDriver ( &DevInstData
);
1178 ClientSideInstallW(IN HWND hWndOwner
,
1179 IN DWORD dwUnknownFlags
,
1180 IN LPWSTR lpNamedPipeName
)
1182 /* NOTE: pNamedPipeName is in the format:
1183 * "\\.\pipe\PNP_Device_Install_Pipe_0.{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}"
1190 IN HINSTANCE hInstance
,
1192 IN LPVOID lpReserved
)
1194 if (dwReason
== DLL_PROCESS_ATTACH
)
1196 INITCOMMONCONTROLSEX InitControls
;
1198 DisableThreadLibraryCalls(hInstance
);
1200 InitControls
.dwSize
= sizeof(INITCOMMONCONTROLSEX
);
1201 InitControls
.dwICC
= ICC_PROGRESS_CLASS
;
1202 InitCommonControlsEx(&InitControls
);
1203 hDllInstance
= hInstance
;