Click here to Skip to main content
15,748,930 members
Articles / Desktop Programming / Win32
Posted 19 Jul 2009


34 bookmarked

Getting the list of drivers running on Windows OS and displaying it in a ListView using pure Win32 calls

Rate me:
Please Sign up or sign in to vote.
4.58/5 (13 votes)
20 Jul 2009CPOL4 min read
This article explains how to get the list of drivers running on Windows OS and display the same in a ListView using Win32 calls.


This article explains the following:

  • How to get the list of drivers running on a Windows machine
  • How to display the list of drivers in a ListView using pure Win32 calls

Note: This article has the latest code for an earlier article, and is updated with the features explained in this article. Please click here to reach my earlier article.

How to get the list of drivers on the machine

Drivers are, in fact, services which run on the OS. To get the list of services, first open the SCM (Service Control Manager) and then call EnumServicesStatus() to enumerate the services.

If more information is required than the ones returned by EnumServicesStatus() (which is the case here), then the service will have to be opened using OpenService() to query some of the required details using QueryServiceConfig(). These calls are made in the function CDriverInfoData::Initialize(). EnumServicesStatus() will get following information:

  • Driver name
  • Driver description
  • Current state of Driver
  • Number of Drivers installed in the system
  • Driver type

Here is the code snippet to enumerate the services:

ENUM_SERVICE_STATUS struct_ServiceStatus;
BOOL b_RetVal = FALSE;
DWORD dw_BytesNeeded;
DWORD dw_ServiceCount;
DWORD dw_ResumeHandle = 0;
DWORD dw_ServiceType;
DWORD dw_ServiceState;
//We are interested only in drivers
dw_ServiceType = SERVICE_DRIVER;
// interested to know about drivers in all states
dw_ServiceState = SERVICE_STATE_ALL;
//Call EnumServicesStatus using the handle returned by OpenSCManager
b_RetVal = ::EnumServicesStatus(h_SCM,
DWORD dw_Error = GetLastError();
// Verify if EnumServicesStatus needs more memory space
if ((b_RetVal == FALSE) || dw_Error == ERROR_MORE_DATA) 
     DWORD dw_Bytes = dw_BytesNeeded + sizeof(ENUM_SERVICE_STATUS);
     lpServiceStatus = new ENUM_SERVICE_STATUS [dw_Bytes];

Despite using EnumServicesStatus(), the driver startup type and path of the driver is still missing. For this, OpenService() will have to be used to open the service and query the information regarding the service using QueryServiceConfig(). Using QueryServiceConfig(), the following additional information will be obtained:

  • Driver startup type
  • Path of driver file

The code snippet to open the service and query the services is shown below:

h_ServiceHandle = NULL;
h_ServiceHandle = OpenService(h_SCM, 
  lpServiceStatus[i].lpServiceName, SERVICE_ALL_ACCESS);
if(NULL != h_ServiceHandle)
     DWORD dwBytesNeeded; 
     BOOL bSuccess=TRUE;
     // Allocate a buffer for the configuration information.
     lpqscBuf = (LPQUERY_SERVICE_CONFIG) LocalAlloc(LPTR, 4096); 
     if (lpqscBuf == NULL) 
         return FALSE;
     // Get the configuration information. 
     if (!QueryServiceConfig(h_ServiceHandle, 
                         4096, // buffer size 
         bSuccess = FALSE; 

Meaning of each field in the Driver Information child window

Image 1

  • Serial No.: Sequence number of list of drivers, just allows interested users to see the count of drivers.
  • Driver Name: This is the driver name and is mostly the same as the driver file name.
  • Description: Description of the driver.
  • Driver Type: Shows the type of driver, whether it’s a Kernel driver or a File System driver.
  • Start Type: Shows the kind of start up. There are four types of startup modes plus one disable state. They are:
    • Auto start- Automatically started by SCM during system startup.
    • Boot start- Started by the system loader in case of drivers.
    • Demand start- Started on demand by calling StartService().
    • System start- Started by the IoInitSystem() call in the case of drivers.
    • Disabled- This state mentions that the driver is disabled.
  • Status: Shows the current status of the driver. The driver could be in one of the following states: Not Running, Starting, Running, Pause is pending, Paused, Continue is pending, Stopping.
  • Image Path: Path of the driver file.

How to create, add headers, and add elements to the list view

The listview is created in the CDriverInfoView class in the function CDriverInfoView::Draw(). The call to create the list view is shown below. The LVS_REPORT style is required to get the header for the columns.

The listview is created by the following call. WC_LISTVIEW should be used as the class name. This is done in the function bool CDriverInfoView::Draw(). The code snippet to do this is shown below:

RECT rect;
GetClientRect(m_hwndParent, &rect);
m_hwndListView = CreateWindowEx(WS_EX_CLIENTEDGE,
                                "", //caption not required
                                WS_CHILD | WS_VISIBLE | LVS_REPORT,
                                rect.right, // width
                                rect.bottom,// height
                               (HINSTANCE) GetWindowLong (m_hwndParent, GWL_HINSTANCE),
// Set the single row select style
                  0, LVS_EX_FULLROWSELECT); // Set style

Adding column headers is done by calling SendMessage() with LVM_INSERTCOLUMN. wParam represents the column number. This is done in the function bool CDriverInfoView::FillData(CDriverInfoData &pDriverInfoData) as shown below:

LVCOLUMN ListviewCol;
memset((void*)&ListviewCol, 0, sizeof(ListviewCol));
ListviewCol.mask = LVCF_TEXT | LVCF_WIDTH; // Mask = 0x40;                       // column width
ListviewCol.pszText = "Serial No";                         
ListviewCol.pszText = "Driver Name";                         

Inserting rows is done by first inserting the first cell in a row with the value and then subsequent cells are set with values. SendMessage with the LVM_INSERTITEM and LVM_SETITEM messages are used to achieve this. The code snippet to do the same is shown below:

memset((void*)&structDriverInfo, 0, sizeof(structDriverInfo));
int i_Col = 0;
TCHAR szSlNo[12];
     // Fill Serial number
     // main item number, this can be considered as row number 
     ListviewItem.iItem = i_Col;
     // Put in the first column
     ListviewItem.iSubItem = DRIVERINFO_SERIALNO_COL;
     memset((void*)szSlNo, 0, sizeof(TCHAR[12]));
     sprintf(szSlNo, "%d", i_Col + 1);
     // Text to display (can be from a char variable) (Items)
     ListviewItem.pszText = TEXT(szSlNo);
     // Send to the Listview
     // Fill Driver Name column
     // main item number, this can be considered as row number 
     ListviewItem.iItem = i_Col;
     ListviewItem.iSubItem = DRIVERINFO_NAME_COL;  // Put in second coluom
     // Text to display (can be from a char variable) (Items)
     ListviewItem.pszText = TEXT(structDriverInfo.DriverName);
     // Send to the Listview

Creation of Driver Information MDI child window

The MDI child window which shows Driver Information is created on getting the command message of ID_INFORMATION_DRIVERINFORMATION in the main frame window proc of SigmaFrameWndProc. Here, a CDriverInfo object is created on the heap. This g_pDriverInfo object is then used to create the window and fill in the list control.

CDriverInfo::CreateDriverInfoWindow() registers the child window and creates the MDI child window. The code snippet is shown below:

MDIChildCreateStruct.szClass = TEXT("SigmaDriverInfoWnd");
MDIChildCreateStruct.szTitle = TEXT("Driver Information");
MDIChildCreateStruct.hOwner  = ghInstance;
MDIChildCreateStruct.x   = CW_USEDEFAULT;
MDIChildCreateStruct.y   = CW_USEDEFAULT;   = CW_USEDEFAULT;   = CW_USEDEFAULT;  = 0;
MDIChildCreateStruct.lParam  = 0;
m_hwndDriverInformation = (HWND) SendMessage(ghMDIClientArea,
                              (LPARAM) (LPMDICREATESTRUCT) &MDIChildCreateStruct) ;

// return if its not possible to create the child window
if(NULL == m_hwndDriverInformation)
    return 0;

MDICREATESTRUCT is used to set the child window parameters. This is passed as the last parameter of SendMessage. SendMessage is used to send WM_MDICREATE messages to the client area of the main frame window.

InitCommonControlsEx() is called to initialize the common controls. This is required for the list control to be created.

Classes and their functionality

  • CDriverInfo – This class holds member elements representing Data and View by means of the CDriverInfoData and CDriverInfoView classes, respectively. A child window is created in this class.
  • CDriverInfoData – This stores the data that should be shown in the listview.
  • CDriverInfoView – This class is used to initialize the listview and fill in data that is available in CDriverInfoData into the listview.


This article had been developed and tested under the following environment only: Lenovo T61 laptop, VC++ 6.0, UNICODE, C++, and XP SP3.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Software Developer (Senior)
India India

Comments and Discussions

GeneralNice, +5 from me Pin
Praveen Kumar Katiyar14-Jul-14 4:51
professionalPraveen Kumar Katiyar14-Jul-14 4:51 
GeneralRe: Nice, +5 from me Pin
Sharath C V14-Jul-14 5:06
professionalSharath C V14-Jul-14 5:06 
Thank you Smile | :)
Suggestionmore updates Pin
Dave Calkins16-Apr-14 16:55
Dave Calkins16-Apr-14 16:55 
GeneralGreat work Pin
icanxy30-Mar-13 22:02
icanxy30-Mar-13 22:02 
GeneralCool Pin
bybeu18-Jul-12 5:41
bybeu18-Jul-12 5:41 
GeneralRe: Cool Pin
Sharath C V18-Jul-12 17:49
professionalSharath C V18-Jul-12 17:49 
GeneralMy vote of 5 Pin
gndnet12-Jul-12 5:32
gndnet12-Jul-12 5:32 
GeneralRe: My vote of 5 Pin
Sharath C V13-Jul-12 19:01
professionalSharath C V13-Jul-12 19:01 
Questionbugs Pin
Dave Calkins26-Jun-12 3:41
Dave Calkins26-Jun-12 3:41 
AnswerRe: bugs Pin
Sharath C V26-Jun-12 20:39
professionalSharath C V26-Jun-12 20:39 
GeneralMy vote of 5 Pin
lgy04722-Feb-12 18:23
lgy04722-Feb-12 18:23 
GeneralRe: My vote of 5 Pin
Sharath C V26-Jun-12 20:33
professionalSharath C V26-Jun-12 20:33 
GeneralNice Article Pin
Vitaly Tomilov14-Oct-10 8:16
Vitaly Tomilov14-Oct-10 8:16 
GeneralRe: Nice Article Pin
Sharath C V17-Oct-10 4:58
professionalSharath C V17-Oct-10 4:58 
GeneralRe: Nice Article Pin
Vitaly Tomilov17-Oct-10 5:09
Vitaly Tomilov17-Oct-10 5:09 
GeneralRe: Nice Article Pin
Sharath C V17-Oct-10 7:41
professionalSharath C V17-Oct-10 7:41 
GeneralRe: Nice Article Pin
Vitaly Tomilov17-Oct-10 16:03
Vitaly Tomilov17-Oct-10 16:03 
GeneralRe: Nice Article Pin
Sharath C V17-Oct-10 19:58
professionalSharath C V17-Oct-10 19:58 
GeneralRe: Nice Article Pin
Sharath C V18-Oct-10 18:48
professionalSharath C V18-Oct-10 18:48 
GeneralRe: Nice Article Pin
Vitaly Tomilov19-Oct-10 3:39
Vitaly Tomilov19-Oct-10 3:39 
GeneralRe: Nice Article Pin
Sharath C V19-Oct-10 7:22
professionalSharath C V19-Oct-10 7:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.