利用 ACPI\ACPI0003设备 判断笔记本还是台式机

这个方式也是来自网上,来源忘记了,找到有一段时间了,这几天刚好用上,
按作者的思路是 笔记本 肯定会有 
硬件ID:           ACPIACPI0003
设备名称:         Microsoft AC Adapter
不管你是否安装电池,都不会影响到
比起 GetSystemPowerStatus 这个函数应该强一点点 下面看代码
 
 
 1 #include "stdafx.h"
 2 #include <windows.h>
 3 #include <setupapi.h>
 4 #include <devguid.h>
 5 #include <regstr.h>
 6 #pragma comment(lib,"setupapi")
 7 
 8 int _tmain(int argc, _TCHAR* argv[])
 9 {
10     int ret = 0;
11 
12     HDEVINFO hDevInfo;
13     SP_DEVINFO_DATA DeviceInfoData;
14     DWORD i;
15 
16     hDevInfo = SetupDiGetClassDevs(NULL,
17         0, 
18         0,
19         DIGCF_PRESENT | DIGCF_ALLCLASSES );
20 
21     if (hDevInfo == INVALID_HANDLE_VALUE)
22     {
23         printf("SetupDiGetClassDevs 失败
");
24         goto end;
25     }
26 
27     TCHAR buffer[4096]={0};
28     DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
29     for (i=0;SetupDiEnumDeviceInfo(hDevInfo,i,
30         &DeviceInfoData);i++)
31     {
32         DWORD DataT;
33         DWORD buffersize = 4096;
34 
35         SetupDiGetDeviceRegistryProperty(
36             hDevInfo,
37             &DeviceInfoData,
38             SPDRP_HARDWAREID,
39             &DataT,
40             (PBYTE)buffer,
41             buffersize,
42             &buffersize);
43 
44         if( wcscmp(buffer, L"ACPI\ACPI0003")==0 )
45         {
46             SetupDiDestroyDeviceInfoList(hDevInfo);
47             printf("找到笔记本电脑直流适配器的设备!
");
48             ret =1 ;
49             goto end;
50         }
51     }
52 
53 
54     if ( GetLastError()!=NO_ERROR &&
55         GetLastError()!=ERROR_NO_MORE_ITEMS )
56     {
57         printf("GetLastError %d
",GetLastError());
58         goto end;
59     }
60 end:
61     SetupDiDestroyDeviceInfoList(hDevInfo);
62     ::system("pause");
63     return ret ;
64 }
 
原文地址:https://www.cnblogs.com/qinsuixin/p/4ca4349682d80f47223e602837710414.html