Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

652 lines
16 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: newdevp.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #define OEMRESOURCE
  11. #include <nt.h>
  12. #include <ntrtl.h>
  13. #include <nturtl.h>
  14. #include <windows.h>
  15. #include <windowsx.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <tchar.h>
  19. #include <string.h>
  20. #include <cpl.h>
  21. #include <prsht.h>
  22. #include <commctrl.h>
  23. #include <setupapi.h>
  24. #include <spapip.h>
  25. #include <cfgmgr32.h>
  26. #include <dlgs.h> // common dlg IDs
  27. #include <shellapi.h>
  28. #include <shlobj.h>
  29. #include <shlwapi.h>
  30. #include <shlobjp.h>
  31. #include <devguid.h>
  32. #include <pnpmgr.h> //REGSTR_VAL_NEW_DEVICE_DESC
  33. #include <lmcons.h>
  34. #include <dsrole.h>
  35. #include <newdev.h>
  36. #include <cdm.h>
  37. #include <wininet.h>
  38. #include <wincrui.h>
  39. #include <regstr.h>
  40. #include <srrestoreptapi.h>
  41. #include <shfusion.h>
  42. #include "resource.h"
  43. #define NEWDEV_CLASS_NAME TEXT("NewDevClass")
  44. #define ARRAYSIZE(array) (sizeof(array) / sizeof(array[0]))
  45. #define SIZECHARS(x) (sizeof((x))/sizeof(TCHAR))
  46. //
  47. // The Install type, these are mutually exclusive.
  48. //
  49. // NDWTYPE_FOUNDNEW - A new device was found. We will do an initial search for drivers with the only
  50. // UI being a subtle balloon tip on the systray. If we don't find a driver in our initial search then
  51. // we will prompt the user with the Found New Hardware wizard.
  52. // NDWTYPE_UPDATE - This is the case where a user is manually updating a driver. For this case we just jump
  53. // directly into the Update Driver Wizard code.
  54. // NDWTYPE_UPDATE_SILENT - This is the case where someone has us silently update a driver for a given device.
  55. // For this case we will do a driver search in the locations specified in the API call. If we don't find a
  56. // driver in these locations then we do NOT bring up the wizard. No UI is shown in this case.
  57. //
  58. #define NDWTYPE_FOUNDNEW 1
  59. #define NDWTYPE_UPDATE 2
  60. #define NDWTYPE_UPDATE_SILENT 3
  61. //
  62. // DEVICE_COUNT_Xxx values are used for the following settings:
  63. // DEVICE_COUNT_FOR_DELAY is the number of devices (times two) that we want to slow
  64. // down the install for so the user can see the UI and have
  65. // time to read it. Once we get past this number of devices
  66. // then we will skip the dealy.
  67. // DEVICE_COUNT_DELAY is the number of milliseconds that we will delay between UI only
  68. // (server side) installs to give the user some time to read the UI.
  69. //
  70. #define DEVICE_COUNT_FOR_DELAY 10
  71. #define DEVICE_COUNT_DELAY 2000
  72. //
  73. // Values used to check if the device, that the Found New Hardware wizard has
  74. // been displayed for, has been installed by some other process. This will
  75. // most likely happen when one user switches desktops and installs the drivers
  76. // on this device.
  77. //
  78. #define INSTALL_COMPLETE_CHECK_TIMERID 1000
  79. #define INSTALL_COMPLETE_CHECK_TIMEOUT 5000
  80. typedef struct _NewDeviceWizardExtension {
  81. HPROPSHEETPAGE hPropSheet;
  82. HPROPSHEETPAGE hPropSheetEnd; // optional
  83. SP_NEWDEVICEWIZARD_DATA DeviceWizardData;
  84. } WIZARDEXTENSION, *PWIZARDEXTENSION;
  85. typedef struct _UpdateDriverInfo {
  86. LPCWSTR InfPathName;
  87. LPCWSTR DisplayName;
  88. BOOL DriverWasUpgraded;
  89. BOOL FromInternet;
  90. TCHAR BackupRegistryKey[MAX_DEVICE_ID_LEN];
  91. TCHAR Description[LINE_LEN];
  92. TCHAR MfgName[LINE_LEN];
  93. TCHAR ProviderName[LINE_LEN];
  94. } UPDATEDRIVERINFO, *PUPDATEDRIVERINFO;
  95. typedef struct _NewDeviceWizard {
  96. HWND hWnd;
  97. HDEVINFO hDeviceInfo;
  98. int EnterInto;
  99. int EnterFrom;
  100. int PrevPage;
  101. int ClassGuidNum;
  102. int ClassGuidSize;
  103. LPGUID ClassGuidList;
  104. LPGUID ClassGuidSelected;
  105. GUID lvClassGuidSelected;
  106. GUID SavedClassGuid;
  107. HCURSOR CurrCursor;
  108. HCURSOR IdcWait;
  109. HCURSOR IdcAppStarting;
  110. HCURSOR IdcArrow;
  111. HFONT hfontTextNormal;
  112. HFONT hfontTextBigBold;
  113. HFONT hfontTextBold;
  114. HANDLE DriverSearchThread;
  115. HANDLE CancelEvent;
  116. DWORD AnalyzeResult;
  117. SP_DEVINFO_DATA DeviceInfoData;
  118. SP_INSTALLWIZARD_DATA InstallDynaWiz;
  119. HPROPSHEETPAGE SelectDevicePage;
  120. SP_CLASSIMAGELIST_DATA ClassImageList;
  121. BOOL Installed;
  122. BOOL ExitDetect;
  123. BOOL SilentMode;
  124. BOOL InstallChilds;
  125. BOOL MultipleDriversFound;
  126. BOOL DoAutoInstall;
  127. BOOL CurrentDriverIsSelected;
  128. BOOL NoDriversFound;
  129. BOOL LaunchTroubleShooter;
  130. BOOL AlreadySearchedWU;
  131. BOOL CallHelpCenter;
  132. BOOL SetRestorePoint;
  133. DWORD Flags;
  134. DWORD InstallType;
  135. DWORD SearchOptions;
  136. DWORD LastError;
  137. DWORD Reboot;
  138. DWORD Capabilities;
  139. PUPDATEDRIVERINFO UpdateDriverInfo;
  140. PVOID MessageHandlerContext;
  141. HMODULE hCdmInstance;
  142. HANDLE hCdmContext;
  143. WIZARDEXTENSION WizExtPreSelect;
  144. WIZARDEXTENSION WizExtSelect;
  145. WIZARDEXTENSION WizExtPreAnalyze;
  146. WIZARDEXTENSION WizExtPostAnalyze;
  147. WIZARDEXTENSION WizExtFinishInstall;
  148. TCHAR ClassName[MAX_CLASS_NAME_LEN];
  149. TCHAR ClassDescription[LINE_LEN];
  150. TCHAR DriverDescription[LINE_LEN];
  151. TCHAR BrowsePath[MAX_PATH];
  152. TCHAR SingleInfPath[MAX_PATH];
  153. TCHAR InstallDeviceInstanceId[MAX_DEVICE_ID_LEN];
  154. } NEWDEVWIZ, *PNEWDEVWIZ;
  155. typedef struct _DELINFNODE {
  156. TCHAR szInf[MAX_PATH];
  157. struct _DELINFNODE *pNext;
  158. } DELINFNODE, *PDELINFNODE;
  159. #define MAX_PASSWORD_TRIES 3
  160. #define NEWDEV_TARGET_NAME TEXT("{36149A20-7CD5-446e-A305-F14D7D6FBC49}")
  161. //
  162. // InstallDeviceInstance Flag values
  163. //
  164. #define IDI_FLAG_SILENTINSTALL 0x00000001
  165. #define IDI_FLAG_SECONDNEWDEVINSTANCE 0x00000002
  166. #define IDI_FLAG_NOBACKUP 0x00000004
  167. #define IDI_FLAG_READONLY_INSTALL 0x00000008
  168. #define IDI_FLAG_NONINTERACTIVE 0x00000010
  169. #define IDI_FLAG_ROLLBACK 0x00000020
  170. #define IDI_FLAG_FORCE 0x00000040
  171. #define IDI_FLAG_MANUALINSTALL 0x00000080
  172. #define IDI_FLAG_SETRESTOREPOINT 0x00000100
  173. //
  174. // RollbackDriver Flag values
  175. //
  176. #define ROLLBACK_FLAG_FORCE 0x00000001
  177. #define ROLLBACK_FLAG_DO_CLEANUP 0x00000002
  178. #define ROLLBACK_BITS 0x00000003
  179. #define REINSTALL_REGKEY TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Reinstall")
  180. #define DEVICEINSTANCEIDS_REGVALUE TEXT("DeviceInstanceIds")
  181. #define REINSTALLSTRING_REGVALUE TEXT("ReinstallString")
  182. BOOL
  183. DoDeviceWizard(
  184. HWND hWnd,
  185. PNEWDEVWIZ NewDevWiz,
  186. BOOL bUpdate
  187. );
  188. BOOL
  189. InstallSelectedDevice(
  190. HWND hwndParent,
  191. HDEVINFO hDeviceInfo,
  192. PDWORD pReboot
  193. );
  194. BOOL
  195. IntializeDeviceMapInfo(
  196. void
  197. );
  198. UINT
  199. GetNextDriveByType(
  200. UINT DriveType,
  201. UINT DriveNumber
  202. );
  203. #define SDT_MAX_TEXT 1024 // Max SetDlgText
  204. //
  205. // from search.c
  206. //
  207. BOOL
  208. FixUpDriverListForInet(
  209. PNEWDEVWIZ NewDevWiz
  210. );
  211. BOOL
  212. IsDriverNodeInteractiveInstall(
  213. PNEWDEVWIZ NewDevWiz,
  214. PSP_DRVINFO_DATA DriverInfoData
  215. );
  216. void
  217. SearchDriveForDrivers(
  218. PNEWDEVWIZ NewDevWiz,
  219. UINT DriveType,
  220. UINT DriveNumber
  221. );
  222. void
  223. SetDriverPath(
  224. PNEWDEVWIZ NewDevWiz,
  225. PCTSTR DriverPath
  226. );
  227. BOOL
  228. IsInstalledDriver(
  229. PNEWDEVWIZ NewDevWiz,
  230. PSP_DRVINFO_DATA DriverInfoData
  231. );
  232. void
  233. DoDriverSearch(
  234. HWND hWnd,
  235. PNEWDEVWIZ NewDevWiz,
  236. ULONG SearchOptions,
  237. DWORD DriverType,
  238. BOOL bAppendToExistingDriverList
  239. );
  240. BOOL
  241. SearchWindowsUpdateCache(
  242. PNEWDEVWIZ NewDevWiz
  243. );
  244. //
  245. // from miscutil.c
  246. //
  247. BOOL
  248. SetClassGuid(
  249. HDEVINFO hDeviceInfo,
  250. PSP_DEVINFO_DATA DeviceInfoData,
  251. LPGUID ClassGuid
  252. );
  253. void
  254. SetDlgText(
  255. HWND hDlg,
  256. int iControl,
  257. int nStartString,
  258. int nEndString
  259. );
  260. void
  261. LoadText(
  262. PTCHAR szText,
  263. int SizeText,
  264. int nStartString,
  265. int nEndString
  266. );
  267. VOID
  268. _OnSysColorChange(
  269. HWND hWnd,
  270. WPARAM wParam,
  271. LPARAM lParam
  272. );
  273. BOOL
  274. NoPrivilegeWarning(
  275. HWND hWnd
  276. );
  277. LONG
  278. NdwBuildClassInfoList(
  279. PNEWDEVWIZ NewDevWiz,
  280. DWORD ClassListFlags
  281. );
  282. void
  283. HideWindowByMove(
  284. HWND hDlg
  285. );
  286. LONG
  287. NdwUnhandledExceptionFilter(
  288. struct _EXCEPTION_POINTERS *ExceptionPointers
  289. );
  290. HPROPSHEETPAGE
  291. CreateWizExtPage(
  292. int PageResourceId,
  293. DLGPROC pfnDlgProc,
  294. PNEWDEVWIZ NewDevWiz
  295. );
  296. BOOL
  297. AddClassWizExtPages(
  298. HWND hwndParentDlg,
  299. PNEWDEVWIZ NewDevWiz,
  300. PSP_NEWDEVICEWIZARD_DATA DeviceWizardData,
  301. DI_FUNCTION InstallFunction,
  302. HPROPSHEETPAGE hIntroPage
  303. );
  304. void
  305. RemoveClassWizExtPages(
  306. HWND hwndParentDlg,
  307. PSP_NEWDEVICEWIZARD_DATA DeviceWizardData
  308. );
  309. BOOL
  310. FileExists(
  311. IN PCTSTR FileName,
  312. OUT PWIN32_FIND_DATA FindData OPTIONAL
  313. );
  314. BOOL
  315. pVerifyUpdateDriverInfoPath(
  316. PNEWDEVWIZ NewDevWiz
  317. );
  318. BOOL
  319. ConcatenatePaths(
  320. IN OUT PTSTR Target,
  321. IN PCTSTR Path,
  322. IN UINT TargetBufferSize,
  323. OUT PUINT RequiredSize OPTIONAL
  324. );
  325. BOOL
  326. RemoveDir(
  327. PTSTR Path
  328. );
  329. RemoveCdmDirectory(
  330. PTSTR CdmDirectory
  331. );
  332. BOOL
  333. pSetupGetDriverDate(
  334. IN PCTSTR DriverVer,
  335. IN OUT PFILETIME pFileTime
  336. );
  337. BOOL
  338. IsInternetAvailable(
  339. HMODULE *hCdmInstance
  340. );
  341. void
  342. CdmLogDriverNotFound(
  343. HMODULE hCdmInstance,
  344. HANDLE hContext,
  345. LPCTSTR DeviceInstanceId,
  346. DWORD Flags
  347. );
  348. BOOL
  349. GetInstalledInf(
  350. IN DEVNODE DevNode, OPTIONAL
  351. IN PTSTR DeviceInstanceId, OPTIONAL
  352. IN OUT PTSTR InfFile,
  353. IN OUT DWORD *Size
  354. );
  355. BOOL
  356. IsInfFromOem(
  357. IN PCTSTR InfFile
  358. );
  359. BOOL
  360. IsConnectedToInternet(
  361. void
  362. );
  363. BOOL
  364. GetLogPnPIdPolicy(
  365. void
  366. );
  367. DWORD
  368. GetSearchOptions(
  369. void
  370. );
  371. VOID
  372. SetSearchOptions(
  373. DWORD SearchOptions
  374. );
  375. BOOL
  376. IsInstallComplete(
  377. HDEVINFO hDevInfo,
  378. PSP_DEVINFO_DATA DeviceInfoData
  379. );
  380. BOOL
  381. GetIsWow64 (
  382. VOID
  383. );
  384. BOOL
  385. OpenCdmContextIfNeeded(
  386. HMODULE *hCdmInstance,
  387. HANDLE *hCdmContext
  388. );
  389. BOOL
  390. pSetSystemRestorePoint(
  391. BOOL Begin,
  392. BOOL CancelOperation,
  393. int RestorePointResourceId
  394. );
  395. BOOL
  396. GetProcessorExtension(
  397. LPTSTR ProcessorExtension,
  398. DWORD ProcessorExtensionSize
  399. );
  400. BOOL
  401. GetGuiSetupInProgress(
  402. VOID
  403. );
  404. DWORD
  405. GetBusInformation(
  406. DEVNODE DevNode
  407. );
  408. PTCHAR
  409. BuildFriendlyName(
  410. DEVINST DevInst,
  411. BOOL UseNewDeviceDesc,
  412. HMACHINE hMachine
  413. );
  414. void
  415. CdmCancelCDMOperation(
  416. HMODULE hCdmInstance
  417. );
  418. extern TCHAR szUnknownDevice[64];
  419. extern USHORT LenUnknownDevice;
  420. extern TCHAR szUnknown[64];
  421. extern USHORT LenUnknown;
  422. extern int g_BlankIconIndex;
  423. extern HMODULE hSrClientDll;
  424. extern HMODULE hNewDev;
  425. extern TCHAR *DevicePath; // default windows inf path
  426. extern BOOL GuiSetupInProgress;
  427. //
  428. // newdev.c, init.c
  429. //
  430. BOOL
  431. InstallDevInst(
  432. HWND hwndParent,
  433. LPCWSTR DeviceInstanceId,
  434. BOOL UpdateDriver,
  435. PDWORD pReboot
  436. );
  437. BOOL
  438. InstallNewDevice(
  439. HWND hwndParent,
  440. LPGUID ClassGuid,
  441. PDWORD pReboot
  442. );
  443. //
  444. // finish.c
  445. //
  446. BOOL
  447. IsNullDriverInstalled(
  448. DEVNODE DevNode
  449. );
  450. DWORD
  451. InstallNullDriver(
  452. HWND hDlg,
  453. PNEWDEVWIZ NewDevWiz,
  454. BOOL FailedInstall
  455. );
  456. //
  457. // update.c
  458. //
  459. void
  460. SetDriverDescription(
  461. HWND hDlg,
  462. int iControl,
  463. PNEWDEVWIZ NewDevWiz
  464. );
  465. void
  466. InstallSilentChilds(
  467. HWND hwndParent,
  468. PNEWDEVWIZ NewDevWiz
  469. );
  470. void
  471. SendMessageToUpdateBalloonInfo(
  472. PTSTR DeviceDesc
  473. );
  474. //
  475. // Driver search options
  476. //
  477. #define SEARCH_DEFAULT_EXCLUDE_OLD_INET 0x00000001 // Search all Default INFs (in %windir%\INF)
  478. // excluding old Internet INFs
  479. #define SEARCH_DEFAULT 0x00000002 // Search all Default INFs (in %windir%\INF)
  480. #define SEARCH_FLOPPY 0x00000004 // Search all INFs on all Floppies on the system
  481. #define SEARCH_CDROM 0x00000008 // Search all INFs on all CD-ROMs on the system
  482. #define SEARCH_DIRECTORY 0x00000010 // Search all INFs in NewDevWiz->BrowsePath directory
  483. #define SEARCH_INET 0x00000020 // Tell Setupapi to call CDM.DLL to see if the
  484. // WU web site has updated drivers for this device.
  485. #define SEARCH_WINDOWSUPDATE 0x00000040 // Search all INFs in NewDevWiz->BrowsePath, but tell
  486. // SETUPAPI.DLL that they are from the Internet.
  487. #define SEARCH_SINGLEINF 0x00000080 // Just search INF in NewDevWiz->SingleInfPath
  488. #define SEARCH_CURRENTDRIVER 0x00000100 // Get the currently installed driver.
  489. #define SEARCH_INET_IF_CONNECTED 0x00000200 // If the machine is connected to the Internet and WU
  490. // appears to have the best driver then basically do
  491. // a SEARCH_INET.
  492. //
  493. // Balloon Tip flags
  494. //
  495. #define TIP_LPARAM_IS_DEVICEINSTANCEID 0x00000001 // lParam is a DeviceInstanceId and not just text
  496. #define TIP_PLAY_SOUND 0x00000002 // play sound when balloon info is displayed
  497. #define TIP_HIDE_BALLOON 0x00000004 // Hide the balloon
  498. //
  499. // Driver List Flags
  500. //
  501. #define DRIVER_LIST_CURRENT_DRIVER 0x00000001 // This is the currently installed driver
  502. #define DRIVER_LIST_SELECTED_DRIVER 0x00000002 // This is the selected/best driver in the list
  503. #define DRIVER_LIST_SIGNED_DRIVER 0x00000004 // This driver is digitally signed.
  504. //
  505. // Private window messages
  506. //
  507. #define WUM_SEARCHDRIVERS (WM_USER+279)
  508. #define WUM_INSTALLCOMPLETE (WM_USER+280)
  509. #define WUM_UPDATEUI (WM_USER+281)
  510. #define WUM_EXIT (WM_USER+282)
  511. #define WUM_INSTALLPROGRESS (WM_USER+283)
  512. //
  513. // Private device install notifications
  514. //
  515. // 0 is used by setupapi to signify the begining of processing a file queue.
  516. // 1 is used by setupapi to notify us that it has processed one file.
  517. //
  518. #define INSTALLOP_COPY 0x00000100
  519. #define INSTALLOP_RENAME 0x00000101
  520. #define INSTALLOP_DELETE 0x00000102
  521. #define INSTALLOP_BACKUP 0x00000103
  522. #define INSTALLOP_SETTEXT 0x00000104
  523. //
  524. // The wizard dialog procs
  525. //
  526. INT_PTR CALLBACK IntroDlgProc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam);
  527. INT_PTR CALLBACK FinishInstallIntroDlgProc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam);
  528. INT_PTR CALLBACK NDW_PickClassDlgProc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam);
  529. INT_PTR CALLBACK NDW_AnalyzeDlgProc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam);
  530. INT_PTR CALLBACK NDW_InstallDevDlgProc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam);
  531. INT_PTR CALLBACK NDW_FinishDlgProc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam);
  532. INT_PTR CALLBACK NDW_SelectDeviceDlgProc(HWND hDlg,UINT wMsg,WPARAM wParam,LPARAM lParam);
  533. LRESULT CALLBACK BalloonInfoProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  534. INT_PTR CALLBACK AdvancedSearchDlgProc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam);
  535. INT_PTR CALLBACK DriverSearchingDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  536. INT_PTR CALLBACK WUPromptDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  537. INT_PTR CALLBACK InstallNewDeviceDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  538. INT_PTR CALLBACK ListDriversDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  539. INT_PTR CALLBACK UseCurrentDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  540. INT_PTR CALLBACK NoDriverDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  541. INT_PTR CALLBACK WizExtPreSelectDlgProc(HWND hDlg, UINT wMsg, WPARAM wParam,LPARAM lParam);
  542. INT_PTR CALLBACK WizExtSelectDlgProc(HWND hDlg, UINT wMsg, WPARAM wParam,LPARAM lParam);
  543. INT_PTR CALLBACK WizExtPreAnalyzeDlgProc(HWND hDlg, UINT wMsg, WPARAM wParam,LPARAM lParam);
  544. INT_PTR CALLBACK WizExtPreAnalyzeEndDlgProc(HWND hDlg, UINT wMsg, WPARAM wParam,LPARAM lParam);
  545. INT_PTR CALLBACK WizExtPostAnalyzeDlgProc(HWND hDlg, UINT wMsg, WPARAM wParam,LPARAM lParam);
  546. INT_PTR CALLBACK WizExtPostAnalyzeEndDlgProc(HWND hDlg, UINT wMsg, WPARAM wParam,LPARAM lParam);
  547. INT_PTR CALLBACK WizExtFinishInstallDlgProc(HWND hDlg, UINT wMsg, WPARAM wParam,LPARAM lParam);
  548. INT_PTR CALLBACK WizExtFinishInstallEndDlgProc(HWND hDlg, UINT wMsg, WPARAM wParam,LPARAM lParam);