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.

101 lines
2.3 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. reload.cpp
  5. Abstract:
  6. Restart a device stack
  7. Revision History:
  8. --*/
  9. #include <windows.h>
  10. #include <setupapi.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include "debug.h"
  14. extern "C" ULONG RestartDevice(
  15. PWCHAR PnpDeviceId
  16. )
  17. {
  18. HDEVINFO DevInfo;
  19. SP_DEVINFO_DATA DevInfoData;
  20. SP_PROPCHANGE_PARAMS PropChangeParams;
  21. ULONG Status;
  22. BOOL ok;
  23. //
  24. // First thing is to create a dev info set
  25. //
  26. DevInfo = SetupDiCreateDeviceInfoList(NULL, // ClassGuid
  27. NULL); // hwndParent
  28. if (DevInfo == INVALID_HANDLE_VALUE)
  29. {
  30. WmipDebugPrint(("SetupDiCreateDeviceInfoList failed %d\n",
  31. GetLastError()));
  32. return(GetLastError());
  33. }
  34. //
  35. // Next step is to add our target device to the dev info set
  36. //
  37. DevInfoData.cbSize = sizeof(DevInfoData);
  38. ok = SetupDiOpenDeviceInfoW(DevInfo,
  39. PnpDeviceId,
  40. NULL, // hwndParent
  41. 0, // OpenFlags
  42. &DevInfoData);
  43. if (ok)
  44. {
  45. memset(&PropChangeParams, 0, sizeof(PropChangeParams));
  46. PropChangeParams.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);
  47. PropChangeParams.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE;
  48. PropChangeParams.StateChange = DICS_PROPCHANGE;
  49. PropChangeParams.Scope = DICS_FLAG_CONFIGSPECIFIC;
  50. PropChangeParams.HwProfile = 0; // current profile
  51. ok = SetupDiSetClassInstallParamsW(DevInfo,
  52. &DevInfoData,
  53. (PSP_CLASSINSTALL_HEADER)&PropChangeParams,
  54. sizeof(SP_PROPCHANGE_PARAMS));
  55. if (ok)
  56. {
  57. ok = SetupDiCallClassInstaller(DIF_PROPERTYCHANGE,
  58. DevInfo,
  59. &DevInfoData);
  60. if (ok)
  61. {
  62. Status = ERROR_SUCCESS;
  63. } else {
  64. WmipDebugPrint(("SetupDiCallClassInstaller failed %d\n", GetLastError()));
  65. Status = GetLastError();
  66. }
  67. } else {
  68. WmipDebugPrint(("SetupDiSetClassInstallParams failed %d\n", GetLastError()));
  69. Status = GetLastError();
  70. }
  71. } else {
  72. printf("SetupDiOpenDeviceInfo failed %d\n", GetLastError());
  73. Status = GetLastError();
  74. }
  75. //
  76. // Finally we need to free the device info set
  77. //
  78. SetupDiDestroyDeviceInfoList(DevInfo);
  79. return(Status);
  80. }