Leaked source code of windows server 2003
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.

625 lines
16 KiB

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