Home > Net >  Check if a Driver is Loaded on Windows
Check if a Driver is Loaded on Windows

Time:09-25

I'm effectively trying to implement the following PowerShell function:

# Checks for the presence of a loaded driver.
function Check-Driver($Driver) {
    ...
}

I've looked around and haven't found a good way to do this. If I had a kernel debugger attached, I could just run lm to see everything, but I want to automate something for our CI to validate things are set up in the correct state. I have come up with one way (below) using verifier.exe but I don't like having to change the state of the system just to check this.

# Checks for the presence of a loaded driver.
function Check-Driver($Driver) {
    $Found = $false
    try {
        $Start = verifier.exe /volatile /adddriver $Driver
        $Stop = verifier.exe /volatile /removedriver $Driver
        $Found = $Stop.Contains("An instance of the service is already running")
    } catch { }
    $Found
}

CodePudding user response:

I found that driverquery /v includes the full file path, so I can use that to match on file name.

# Checks for the presence of a loaded driver.
function Check-Driver($Driver) {
    $Found = $false
    try {
        $Found = (driverquery /v | Select-String $Driver).Matches[0].Success
    } catch { }
    $Found
}
  • Related