Enable/Disable device driver via command line

9

I did a google search and found tools like devcon and devmanview but they are only useful to disable/enable the device not the device driver. What I want to do is be able to disable/enable a particular device driver via command line. Anybody know any tool which can help me do this?

In my case, I actually want to disable/enable a Nvme Mass storage device driver.

Update- I tried using the sc.exe suggested, but I didn't succeed in stopping the driver. Any help?

    C:\Users\Administrator>sc query nvme
    SERVICE_NAME: nvme
    TYPE               : 1  KERNEL_DRIVER
    STATE              : 4  RUNNING
                            (STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN)
    WIN32_EXIT_CODE    : 0  (0x0)
    SERVICE_EXIT_CODE  : 0  (0x0)
    CHECKPOINT         : 0x0
    WAIT_HINT          : 0x0

    C:\Users\Administrator>sc stop nvme [SC] ControlService FAILED 1052:
    The requested control is not valid for this service.

kate

Posted 2016-02-16T23:04:58.800

Reputation: 103

What is Windows 2012? – DavidPostill – 2016-02-16T23:10:37.130

I meant Windows Server 2012 https://www.microsoft.com/en-us/server-cloud/products/windows-server-2012-r2/Overview.aspx

– kate – 2016-02-16T23:15:28.180

Fixed it for you. We don't need version in the title, I fixed the tags ;) – DavidPostill – 2016-02-16T23:17:20.313

I don't think you can enable/disable drivers only devices. What are you actually trying to achieve? – DavidPostill – 2016-02-16T23:20:24.117

1@DavidPostill Actually, some drivers can be stopped (even file system drivers!) - Kate, what's the output of sc queryex type= driver | findstr /i service_name (all literal); is the desired driver in there? – Ben N – 2016-02-16T23:22:09.483

@BenN I did that and I have a long list of service names, how can i map these service names to the driver I want to manipulate? Any help? – kate – 2016-02-16T23:51:30.160

@BenN I think I found it! :) Missed it the first time! its just 'nvme'! :) – kate – 2016-02-16T23:54:13.627

@DavidPostill I am trying to reset the nvme drive, specifically issue a controller reset by disabling/re-enabling the driver! – kate – 2016-02-16T23:57:27.000

Answers

4

You can use the sc.exe utility for this.

sc query type= driver | findstr WHAT_IM_LOOKING_FOR

If you find what you're looking for, you can at stop the driver with:

sc stop EXACT_DRIVER_NAME_AS_LISTED_BY_QUERY

Obviously you'll need a shell with administrator privileges to do this. If you're looking to automate this at login, you can make a batch file and install it as an administrator with task scheduler. Tasks installed that require administrator privileges, but were installed by an administrator, will not prompt for privileges at startup, but will be granted them automatically.

user72945

Posted 2016-02-16T23:04:58.800

Reputation:

2I am having trouble with this -\n C:\Users\Administrator>sc.exe query type= driver | findstr nvme SERVICE_NAME: nvme DISPLAY_NAME: nvme

C:\Users\Administrator>sc stop nvme [SC] ControlService FAILED 1052:

The requested control is not valid for this service. – kate – 2016-02-17T01:15:26.657

1@Kate I guess then that the driver is not stoppable. – None – 2016-02-17T03:13:55.897

@kate actually from your update, the service is listed as STOPPABLE, so I suspect the issue is something else. I'd recommend a new question, as this is now technically a separate issue. – None – 2016-02-17T03:14:55.423

1

I was able to install the free 'devcon.exe' utility inside the Windows 10 driver kit from Microsoft.

This utility will let you enable / disable whatever you see in Driver Manager. In my case, I found that the High Definition Audio Bus from Microsoft on Windows 10 was badly written and was consuming 10% of CPU always. I disabled it with:

devcon.exe disable PCI\VEN_8086"&"DEV_9D71*

You have to run this as administrator, so I put this into a .bat file, and made a 'run as administrator' shortcut to it.

Jeff Winkler

Posted 2016-02-16T23:04:58.800

Reputation: 11

0

i'm able to stop the driver

C:\Windows\system32>sc stop kmd
SERVICE_NAME: kmd
        TYPE               : 1  KERNEL_DRIVER
        STATE              : 3  STOP_PENDING
                                (STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0

But the corresponding GUI is not updated in devmgmt.msc Usually when i disable the driver in Device Managenement, down arrow on the driver icon appears to confirm the driver is disabled.

with the command line sc, the down arrow does not appear

corning

Posted 2016-02-16T23:04:58.800

Reputation: 1

0

Try C:\> NET STOP drivername .

Jamie Hanrahan

Posted 2016-02-16T23:04:58.800

Reputation: 19 777