C++ Learning Community Forum
September 11, 2010, 01:55:19 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Hello. Smiley
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Getting a list of installed hardware devices  (Read 444 times)
Adam Athari
N00b!!1
*
Posts: 1


View Profile
« on: April 30, 2007, 09:07:47 PM »

Hi,
Is there a way to programatically query Windows to see if a particular device is installed or not.

And is there a way to tell windows to load or unload a driver?

Thanks

Adam
Logged
FrozenKnight
Extends without bound
Global Moderator
Dr. of C++ology
*****
Posts: 558


Do it yourself it's the only way to learn.


View Profile
« Reply #1 on: April 30, 2007, 10:14:57 PM »

CM_Get_Device_ID_List

hope that helps. only took about a min of searching on msdn.
Logged


Imagine the impossible, then make it happen.
adeyblue
Dr. of C++ology
****
Posts: 653

Taming the turntables a beat at a time


View Profile WWW
« Reply #2 on: April 30, 2007, 10:59:36 PM »

You can probably modify this example to check if your device is installed. The example gives the friendly names though not device ids. Generally you'll want to look through the setup api for this sort of thing.

Since drivers are handled by the service control manager, you might be able to use StartService to start / load a driver and ControlService with SERVICE_CONTROL_STOP to stop / unload it. EDIT: Yep it's possible, this code unloads the beep driver before loading it again:
Code
GeSHi (cpp):
#include <windows.h>
 
int main()
{
   SC_HANDLE scM = OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_ALL_ACCESS);
   if(scM)
   {
       SC_HANDLE beep = OpenService(scM, "beep", SERVICE_ALL_ACCESS);
       if(beep)
       {
           SERVICE_STATUS status = {0};
           ControlService(beep, SERVICE_CONTROL_STOP, &status);
           Sleep(5000);
           StartService(beep, 0, NULL);
           CloseServiceHandle(beep);
       }
       CloseServiceHandle(scM);
 }
}
 
Created by GeSHI 1.0.7.18
« Last Edit: April 30, 2007, 11:14:13 PM by adeyblue » Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!