日韩精品中文字幕一区二区-日韩精品中文字幕一区-日韩精品中文字幕视频-日韩精品在线一区二区三区-第一页在线-第一福利视频

當前位置:首頁文章首頁 IT學院 IT技術

全自動安裝卸載驅動程序的源程序

作者:  來源:  發(fā)布時間:2011-12-15 0:53:30  點擊:
   {

   return DisplayError(TEXT(CreateDeviceInfoList));

   }

   //

   // Now create the element.

   // Use the Class GUID and Name from the INF file.

   //

   DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);

   if (!SetupDiCreateDeviceInfo(DeviceInfoSet,

   ClassName,

   &ClassGUID,

   NULL,

   0,

   DICD_GENERATE_ID,

   &DeviceInfoData))

   {

   DisplayError(TEXT(CreateDeviceInfo));

   goto cleanup_DeviceInfo;

   }

   //

   // Add the HardwareID to the Device's HardwareID property.

   //

   if(!SetupDiSetDeviceRegistryProperty(DeviceInfoSet,

   &DeviceInfoData,

   SPDRP_HARDWAREID,

   (LPBYTE)HardwareId,

   (lstrlen(HardwareId)+1+1)*sizeof(TCHAR)))

   {

   DisplayError(TEXT(SetDeviceRegistryProperty));

   goto cleanup_DeviceInfo;

   }

   //

   // Transform the registry element into an actual devnode

   // in the PnP HW tree.

   //

   if (!SetupDiCallClassInstaller(DIF_REGISTERDEVICE,

   DeviceInfoSet,

   &DeviceInfoData))

   {

   DisplayError(TEXT(CallClassInstaller(REGISTERDEVICE)));

   goto cleanup_DeviceInfo;

   }

   //

   // The element is now registered. We must explicitly remove the

   // device using DIF_REMOVE, if we encounter any failure from now on.

   //

   //

   // Install the Driver.

   //

   if (!UpdateDriverForPlugAndPlayDevices(0,

   HardwareId,

   INFFile,

   INSTALLFLAG_FORCE,

   RebootRequired))

   {

   DWORD err = GetLastError();

   DisplayError(TEXT(UpdateDriverForPlugAndPlayDevices));

   if (!SetupDiCallClassInstaller(

   DIF_REMOVE,

   DeviceInfoSet,

   &DeviceInfoData))

   {

   DisplayError(TEXT(CallClassInstaller(REMOVE)));

   }

   SetLastError(err);

   }

   //

   // Cleanup.

   //

  cleanup_DeviceInfo:

   err = GetLastError();

   SetupDiDestroyDeviceInfoList(DeviceInfoSet);

   SetLastError(err);

   return err == NO_ERROR;

  }

  int InstallDriver(_TCHAR *InfName, _TCHAR *HardwareID)

  {

   WIN32_FIND_DATA FindFileData;

   BOOL RebootRequired = 0; // Must be cleared.

   _TCHAR *FName, *HWID;

   FName = InfName;

   HWID = HardwareID;

   if (FindFirstFile(FName,&FindFileData)==INVALID_HANDLE_VALUE)

   {

   //_tprintf(TEXT( File not found.\\n));

   //_tprintf(TEXT(usage: install \\n));

   return 2; // Install Failure

   }

   //

   // Look to see if this device allready exists.

   //

   if (FindExistingDevice(HWID))

   {

   //

   // No Need to Create a Device Node, just call our API.

   //

   if (!UpdateDriverForPlugAndPlayDevices(0, // No Window Handle

   HWID, // Hardware ID

   FName, // FileName

   INSTALLFLAG_FORCE,

   &RebootRequired))

   {

   DisplayError(TEXT(UpdateDriverForPlugAndPlayDevices));

   return 2; // Install Failure

   }

   }

   else

   {

   if (GetLastError()!= ERROR_NO_MORE_ITEMS)

   {

   //

   // An unknown failure from FindExistingDevice()

   //

   //_tprintf(TEXT((IERROR_NO_MORE_ITEMS)\\n));

   //_tprintf(TEXT((Install Failure! Code = 2)\\n));

   return 2; // Install Failure

   }

   //

   // Driver Does not exist, Create and call the API.

   // HardwareID must be a multi-sz string, which argv[2] is.

   //

   if (!InstallRootEnumeratedDriver(HWID, // HardwareID

   FName, // FileName

   &RebootRequired))

   {

   //_tprintf(TEXT((InstallRootEnumeratedDriver Failure! Code = 2)\\n

  ));

   return 2; // Install Failure

   }

   }

   //_tprintf(TEXT(Driver Installed successfully.\\n));

   if (RebootRequired)

   {

   //_tprintf(TEXT((Reboot Required)\\n));

   return 1; // Install Success, reboot required.

   }

   return 0; // Install Success, no reboot required.

  }

  int RemoveDriver(_TCHAR *HardwareID)

  {

   HDEVINFO DeviceInfoSet;

   SP_DEVINFO_DATA DeviceInfoData;

   DWORD i,err;

   DeviceInfoSet = SetupDiGetClassDevs(NULL, // All Classes

   0,

   0,

   DIGCF_ALLCLASSES | DIGCF_PRESENT ); // All devices present on system

   if (DeviceInfoSet == INVALID_HANDLE_VALUE)

   {

   DisplayError(TEXT(GetClassDevs(All Present Devices)));

   return 1;

   }

   //

   // Enumerate through all Devices.

   //

   DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);

   for (i=0;SetupDiEnumDeviceInfo(DeviceInfoSet,i,&DeviceInfoData);i++)

首頁 上一頁 [1] [2] [3]  下一頁 尾頁
上一篇:USB 驅動自動卸載方法 下一篇:

文章評論

軟件按字母排列: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
主站蜘蛛池模板: 辐射避难所掉脑袋问题答案| 必修一英语电子课本外研版| 黑色的人生中文翻译版| 员工的秘密| 澳大利亚《囚犯》| www.douyin.com| 艋舺| 翟潇闻个人介绍| 云月之恋简谱| 模特走秀视频| 1988版绝代双骄国语免费观看| 红岩下的追捕电视剧| 花宵| 挠丝袜| 姐姐的秘密电影| 七上语文背诵清单表| 屈楚萧| 广场舞100首视频| 易烊千玺是哪里人| 日本大片网站| 洗冤录粤语| 电影《正青春》| 单敬尧| 漫画启示作文五年级| 荒山之夜| 贝加尔湖畔钢琴谱| 弯刀| 我的冠军男友在线看全集完整| 白雪公主在线| 洛城僵尸| 电影疯狂| 飞龙猛将演员表| 纵情欲海电影| 捆绑上天堂电影| 蕾切尔·薇兹| 口述与子性细节过程| 低糖食物一览表| 纵横欲海| 黄漪钧| 下载绿幕助手| 妈妈1|