1.列舉系統裝置
hdevinfo hdevinfo;
sp_devinfo_data deviceinfodata;
dword dwdevid;
// 得到所有裝置 hdevinfo
hdevinfo = setupdigetclassdevs(null, 0, 0,
digcf_present | digcf_allclasses);
//根據此處引數不同可分類列舉裝置,這裡列舉了所有裝置
if (hdevinfo == invalid_handle_value)
deviceinfodata.cbsize = sizeof(sp_devinfo_data);
for (dwdevid = 0; setupdienumdeviceinfo(hdevinfo, dwdevid, &deviceinfodata); dwdevid++)
else
break;
}tchar strguid[512] = _t("");//裝置guid
_stprintf_s(strguid, _t("%x-%x-%x-%x%x%x%x%x%x%x%x "),
deviceinfodata.classguid.data1,
deviceinfodata.classguid.data2,
deviceinfodata.classguid.data3,
deviceinfodata.classguid.data4[0],
deviceinfodata.classguid.data4[1],
deviceinfodata.classguid.data4[2],
deviceinfodata.classguid.data4[3],
deviceinfodata.classguid.data4[4],
deviceinfodata.classguid.data4[5],
deviceinfodata.classguid.data4[6],
deviceinfodata.classguid.data4[7]);
deviceinfo.devid = dwdevid;//裝置id
deviceinfo.bdisabled =
isdisabled(dwdevid, hdevinfo);//是否已禁用
deviceinfo.bdisableable =
isdisableable(dwdevid, hdevinfo);//是否可禁用
wcscpy_s(deviceinfo.devicename, buffer);,//裝置名
if (buffer)
heapfree(getprocessheap(), 0, buffer);
}if (getlasterror() != no_error &&
getlasterror() != error_no_more_items)
setupdidestroydeviceinfolist(hdevinfo);
return true;
//根據裝置id判斷指定裝置是否可禁用
boolisdisableable(dword dwdevid, hdevinfo hdevinfo)
;dword dwdevstatus, dwproblem;
if (!setupdienumdeviceinfo(hdevinfo, dwdevid, &devinfodata))
//查詢裝置狀態
if (cm_get_devnode_status(&dwdevstatus, &dwproblem, devinfodata.devinst, 0) != cr_success)
return ((dwdevstatus & dn_disableable) && (dwproblem != cm_prob_hardware_disabled));
}//根據裝置id判斷指定裝置是否已禁用
bool isdisabled(dword dwdevid, hdevinfo hdevinfo)
;dword dwdevstatus, dwproblem;
if (!setupdienumdeviceinfo(hdevinfo, dwdevid, &devinfodata))
//查詢裝置狀態
if (cm_get_devnode_status(&dwdevstatus, &dwproblem, devinfodata.devinst, 0) != cr_success)
return ((dwdevstatus & dn_has_problem) && (dwproblem == cm_prob_disabled));
}//根據裝置id以及dwnewstate:dics_enable,dics_disable兩個引數來啟用,禁用裝置
bool statechange(dword dwnewstate, dword dwdevid, hdevinfo hdevinfo)
;sp_devinstall_params devparams;
//查詢裝置資訊
if (!setupdienumdeviceinfo(hdevinfo, dwdevid, &devinfodata))
//設定裝置屬性變化引數
propchangeparams.classinstallheader.cbsize = sizeof(sp_classinstall_header);
propchangeparams.classinstallheader.installfunction = dif_propertychange;
propchangeparams.scope = dics_flag_global; //使修改的屬性儲存在所有的硬體屬性檔案
propchangeparams.statechange = dwnewstate;
propchangeparams.hwprofile = 0;
//改變裝置屬性
if (!setupdisetclassinstallparams(hdevinfo,
&devinfodata,
(sp_classinstall_header *)&propchangeparams,
sizeof(propchangeparams)))
propchangeparams.classinstallheader.cbsize = sizeof(sp_classinstall_header);
propchangeparams.classinstallheader.installfunction = dif_propertychange;
propchangeparams.scope = dics_flag_configspecific;//使修改的屬性儲存在指定的屬性檔案
propchangeparams.statechange = dwnewstate;
propchangeparams.hwprofile = 0;
//改變裝置屬性並呼叫安裝服務
windows 實現UDP廣播獲取裝置
1 獲取本機所有ip,把ip的最後乙個字段值改為255,去掉重複的ip 2 遍歷所有ip進行廣播 broadcastdemo.cpp 定義控制台應用程式的入口點。include stdafx.h include include include include pragma comment lib,w...
windows 系統遍歷USB裝置 VID和PID
常用裝置介面類guid identifier class guid guid devinte ce usb device guid devinte ce usb host controller guid devinte ce usb hub guid devinte ce net guid devi...
windows系統實現Tomcat集群
tomcat集群 主要是負載均衡 高可用也有 nginx 功能 提供http服務,是乙個web容器 apache,iis asp.net tomcat 功能 提供http和servlet解析服務,是web容器 servlet jsp容器 生產環境下 nginx tomcat 通過nginx將請求分發...