獲取裝置管理器的資訊

2021-08-17 09:23:53 字數 3911 閱讀 2577

有些時候需要先獲取裝置管理器裡面的硬體資訊,才能執行對應的操作,簡單的鼓搗了一下,貼出來共享。

具體有兩個方法,大致來說差不多,流程一樣 ,懶得整理了,直接貼出來原始體。

// printdeviceinfo.cpp : 定義控制台應用程式的入口點。

//

#include "stdafx.h"

#include

#include

#pragma comment(lib, "setupapi.lib")

voidprintdevicesinfo1()

;

sp_classimagelist_data _spimagedata = ;

_spimagedata.cbsize =sizeof(sp_classimagelist_data);

setupdigetclassimagelist(&_spimagedata);

shortwindex = 0;

sp_devinfo_data spdevinfodata = ;

spdevinfodata.cbsize =sizeof(sp_devinfo_data);

while(1)

;

intwimageidx = 0;

shortwitem = 0;

if(!setupdigetdeviceregistrypropertya(hdevinfo, &spdevinfodata, spdrp_class, null, (pbyte)szbuf, max_path, 0))

;

if(setupdigetclassimageindex(&_spimagedata, &spdevinfodata.classguid, &wimageidx))

;

dworddwrequiresize;

//

if(!setupdigetclassdescription(&spdevinfodata.classguid, szbuf, max_path, &dwrequiresize))

;

printf("class:%s\r\n", szbuf);

if(setupdigetdeviceregistryproperty(hdevinfo,&spdevinfodata, spdrp_friendlyname, null, (pbyte)szname, max_path - 1, 0))

elseif(setupdigetdeviceregistryproperty(hdevinfo,&spdevinfodata, spdrp_devicedesc, null, (pbyte)szname, max_path - 1, 0))

;

};

}

else

break;

windex++;

};

setupdidestroyclassimagelist(&_spimagedata);

}

int_tmain(intargc, _tchar* argv)

;

charszdescbuf[max_path] = ;

// 獲取類名

if(!setupdigetdeviceregistryproperty(hdevinfo, &deviceinfodata, spdrp_class, null, (pbyte)szclassbuf, max_path - 1, null))

continue;

//獲取裝置描述資訊

if(!setupdigetdeviceregistryproperty(hdevinfo, &deviceinfodata, spdrp_devicedesc, null, (pbyte)szdescbuf, max_path - 1, null))

continue;

printf("class:%s\r\ndesc:%s\r\n\r\n", szclassbuf, szdescbuf);

}

//  釋放

setupdidestroydeviceinfolist(hdevinfo);

getchar();

return0;

}

裝置管理器總結

enable和disable的問題都解決了,剩下的問題都是關於怎麼生成裝置樹並呈現出來的問題,windows作業系統應該有現成的庫函式或者api呼叫,能把整個一棵樹一次性調出。但是c 開發環境下很少使用指標鍊錶的概念,就算系統中有這麼一棵樹,那麼也應該是用鍊錶串起來的,在c 這邊我們要怎麼接收呢?官...

Powershell 檢測裝置管理器

下圖為其中乙個裝置的詳細資訊 name存在且 pnpclass 為 null 的裝置為其他裝置 other devices status 為 error 的裝置為未正常工作裝置 yellow bang pnpclass 表示裝置所屬類 通過比較資料的改變來檢測裝置的變化 function catch...

獲取串列埠裝置名稱 獲取裝置管理器裡的硬體名稱 轉

簡介 在串列埠通訊的程式中,如果pc上同時連線有多個串列埠,那麼從應用程式裡開啟串列埠時,就很難知道是哪乙個串列埠,這時候就必須要通過裝置管理器去檢視串列埠名稱,這份 就是解決這個問題,呼叫系統api,讀取串列埠裝置的名稱和串口號,不需要再從裝置管理器裡去查詢串列埠。程式關鍵部分如下 1 using...