Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

How do you enable/disable a driver in Windows?

by DrWhy (Chaplain)
on Feb 06, 2007 at 00:24 UTC ( [id://598459]=perlquestion: print w/replies, xml ) Need Help??

DrWhy has asked for the wisdom of the Perl Monks concerning the following question:

I need to disable and re-enable a hardware driver in a test script. This is to allow me to test an application's behavior when the hardware (a USB key in this particular case) is available or unavailable or becomes unavailable during normal operations. (I don't want to have to stand next to the machine and manually pull out the the usb device at the right time when I run the script :)

Does any monk out there know how this can be done inside a Perl script? I'm looking for a solution that works on modern Windows OS's (anything newer than NT), though a Linux/*nix solution would be of interest as well.

--DrWhy

"If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."

  • Comment on How do you enable/disable a driver in Windows?

Replies are listed 'Best First'.
Re: How do you enable/disable a driver in Windows?
by BrowserUk (Patriarch) on Feb 06, 2007 at 02:58 UTC
      I'm far from being a Windows guru, so feel free to correct me if I'm wrong, but I'm not sure services are what I'm talking about. I want to turn off the driver software that allows the OS to recognize and communicate with a USB device (actually a specific type of USB device, but that's probably not relevant). Is it possible that each device driver also has a service associated with it that? I've not seen that before. What I'm talking about is doing what you would normally do by hand by going to the System control panel, clicking on the 'Hardware' link and then drilling down to the details for the specific driver in question and then selecting 'disable' from the dropdown menu at the bottom of the window.

      --DrWhy

      "If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."

        Yes. You are looking to disable a device driver, not a service.

        The particular APIs needed do this are located in DEVMGR.DLL, probably one of DeviceProperties(A|W), or DevicePropertiesEx(A|W) or DeviceAdvancedProperties(A|W). However, these APIs are officially undocumented, so working out what the parameters are would be extremely difficult.

        There are various hardware and DD developer kits available that provide (indirect but documented) access to these APIs, (Windows Device Testing Framework (WDTF); Device Driver Kits (DDKs); WDK etc. ), but which one you would need and whether it would cost money depends upon the version and age of the OS etc. I assume this is not the route you are looking to take.

        BTW. The description you give of how to do this manually indicates that you are working with a fairly old version of Windows? On XP (and I think on 2000/2003), the interface changed. You now do this manually via:

        Administrative tools->Computer management->Device Manager

        That means that it may be possible to adjust these settings programmatically via the Windows Management Interface (WMI) on these later systems--but that probably doesn't help if you're working with NT or earlier.

        It's also possible to disable them by adjusting the values of the appropriate registry entries (Win32API::Registry), but I think that you then need a re-boot for it to take affect.

        Ultimately, I'm guessing that what you are trying to do is disable the use of USB thumb drives and similar "security risk" devices for corporate desktops? If so, the best way is to do this through the application of appropriate group policies and articles of this nature may be more appropriate to your needs.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://598459]
Approved by polettix
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2025-03-27 16:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When you first encountered Perl, which feature amazed you the most?










    Results (70 votes). Check out past polls.

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.