最新消息

[公告2014/05/30] 如有需要將部落格中,任何一篇文章的程式碼使用在商業用途,請與我聯繫。

[公告2015/04/26] Line版的 iInfo程式與投資應用 群組已上線想加入的朋友們,請先查看 "入群須知" 再與我聯繫 Line : aminwhite5168,加入請告知身分與回答 "入群須知" 的問題。

[公告2018/04/22] 台北 Python + Excel VBA 金融資訊爬蟲課程,課程如網頁內容 金融資訊爬蟲班:台北班 Python 金融資訊爬蟲、EXCEL VBA 金融資訊爬蟲

[公告2019/01/08] 請注意:我再次重申,部落格文章的程式碼,是要提供各位參考與學習,一旦網頁改版請自行修改,別要求東要求西要我主動修改,你們用我寫東西賺錢了、交差了,請問有分我一杯羹嗎?既然賺錢沒分我,請問有什麼理由要求我修改,如果沒能力改,就花錢來找我上課。

[公告2019/12/01] 若各位有 Excel VBA 案子開發需求,歡迎與我聯繫,可接案處理。

[公告2020/05/22] 頁面載入速度慢,起因為部分JS來源(alexgorbatchev.com)失效導致頁面載入變慢,目前已做調整,請多見諒。

2013年5月8日 星期三

查詢裝置與Driver間的連結狀態CM_Get_DevNode_Status

有時候我們可能會想了解一個裝置與驅動程式之間的狀態,才能正常操作該裝置?
這時候就可以使用Devcon來幫助我們了解裝置與驅動程式間是否正常運作,但我們也可以自己寫一個類似的小工具來使用。
使用只會顯示ERROR Code,不會顯示ERROR Message,但自己寫的工具就可以加入更多的資訊,在適當的時候協助釐清問題的根本。
以下貼出使用的程式碼與ERROR Code對應的ERROR Message
BOOL ListALLDevice()
{
 HDEVINFO hDevInfo;
 DWORD i, j;
 BOOL bFound = FALSE;
 DWORD Status, Problem; 
 CONFIGRET cr = CR_SUCCESS;
 CHAR * cStatus[] = {"Hardware ID", "Hardware Name"};
 UCHAR ucSPDRP[5];

 ucSPDRP[0] = SPDRP_HARDWAREID;
 ucSPDRP[1] = SPDRP_DEVICEDESC;

 hDevInfo = SetupDiGetClassDevs(NULL,
     0,
     0,
     DIGCF_PRESENT | DIGCF_ALLCLASSES );

 if (hDevInfo == INVALID_HANDLE_VALUE )
 {
  printf("Unable to enumerate device\n");
  return FALSE;
 }

 SP_DEVINFO_DATA  DeviceInfoData;
 DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);

 for ( i = 0 ; SetupDiEnumDeviceInfo( hDevInfo, i, &DeviceInfoData ) ; i++ ) 
 {
  for(j = 0 ; j < 2 ; j++)
  {
   DWORD DataType;
   LPSTR Buffer = NULL;
   DWORD BufferSize = 0;

   while (!SetupDiGetDeviceRegistryProperty(hDevInfo,
        &DeviceInfoData,
        ucSPDRP[j],
        &DataType,
        ( PBYTE ) Buffer,
        BufferSize,
        &BufferSize ) ) {
    if ( GetLastError()  == ERROR_INSUFFICIENT_BUFFER ) 
    {
     // Change the buffer size.
     if ( Buffer ) LocalFree( Buffer );
     Buffer = (LPSTR) LocalAlloc( LPTR, BufferSize * 2 );
    } 
    else      
     break;// Insert error handling here.
   }
   printf( "%s : %s\n", cStatus[j], (const char *)Buffer);
   if ( Buffer ) LocalFree( Buffer );
  }
  
  cr = CM_Get_DevNode_Status(&Status, &Problem, DeviceInfoData.DevInst, 0);
  printf("Device status :\n");
  if(Status & DN_HAS_PROBLEM)
  {
   printf("\tERROR Message : %s\n", DeviceErrorMessage[Problem]);
   printf("\tERROR code : %d\n", Problem);
  }
  else
   printf("\tDevice is running.\n");

  printf("\n");
 }
 SetupDiDestroyDeviceInfoList(hDevInfo);

 return TRUE;
}

ERROR Code與ERROR Message對應表
ERROR Code
ERROR Message
1
This device is not configured correctly
2
Windows could not load the driver for this device because the computer is reporting two bus types
3
The driver for this device may be bad, or your system may be running low on memory or other resources
4
This device is not working properly because one of its drivers may be bad, or your registry may be bad
5
The driver for this device requested a resource that Windows does not know how to handle
6
Another device is using the resources this device needs
7
The drivers for this device need to be reinstalled
8
This device is not working properly because Windows cannot load the file that loads the drivers for the device
9
This device is not working properly because the BIOS in your computer is reporting the resources for the device incorrectly
10
This device is either not present, not working properly, or does not have all the drivers installed
11
Windows stopped responding while attempting to start this device, and therefore will never attempt to start this device again
12
This device cannot find any free resources to use
13
This device is either not present, not working properly, or does not have all the drivers installed
14
This device cannot work properly until you restart your computer
15
This device is causing a resource conflict
16
Windows could not identify all the resources this device uses
17
The driver information file is telling this child device to use a resource that the parent device does not have or recognize
18
The drivers for this device need to be reinstalled 
19
Your registry may be bad Windows could not load one of the drivers for this device
20
Windows could not load one of the drivers for this device
21
Windows is removing this device
22
This device is disabled This device is not started
23
This display adapter is functioning correctly This device is not started
24
This device is either not present, not working properly, or does not have all the drivers installed
25
Windows is in the process of setting up this device
26
Windows is in the process of setting up this device
27
Windows cant specify the resources for this device
28
The drivers for this device are not installed
29
This device is disabled because the BIOS for the device did not give it any resources
30
This device is using an Interrupt Request IRQ resource that is in use by another device and cannot be shared
31
This device is not working properly because is not working properly
32
Windows cannot install the drivers for this device because it cannot access the drive or network location that has the setup files on it
33
This device isn’t responding to its driver
34
Windows cannot determine the settings for this device
35
Your computer’s system firmware does not include enough information to properly configure and use this device 
36
This device is requesting a PCI interrupt but is configured for an ISA interrupt 
37
Windows cannot initialize the device driver for this hardware
38
Windows cannot load the device driver for this hardware because a previous instance of the device driver is still in memory
39
Windows cannot load the device driver for this hardware The driver may be corrupted or missing
40
Windows cannot access this hardware because its service key information in the registry is missing or recorded incorrectly 
41
Windows successfully loaded the device driver for this hardware but cannot find the hardware device
42
Windows cannot load the device driver for this hardware because there is a duplicate device already running in the system
43
Windows has stopped this device because it has reported problems
44
An application or service has shut down this hardware device
45
Currently, this hardware device is not connected to the computer 
46
Windows cannot gain access to this hardware device because the operating system is in the process of shutting down
47
Windows cannot use this hardware device because it has been prepared for "safe removal", but it has not been removed from the computer
48
The software for this device has been blocked from starting because it is known to have problems with Windows
49
Windows cannot start new hardware devices because the system hive is too large exceeds the Registry Size Limit) 
50
Failed to apply one or more registry properties
51
This device is currently waiting on another device or set of devices to start
52
Windows cannot verify the digital signature for the drivers required for this device
53

沒有留言:

張貼留言