twainwia

Force terminate WIA or TWAIN driver (scanner)


I'm having a pretty annoying issue. When I try to silent install a program, that program depends on the WIA or TWAIN driver (for scanners) NOT being "in use". The problem is that driver can be "in use" even after the scanner is unplugged from the computer (if it was plugged in before, the driver is used and doesn't stop being in use after unplugging)

My question is, to your knowledge, what controls this WIA / TWAIN driver? Is it a service I can force close or a process?

I have found these 2 services for WIA :

stisvc
WiaRpc

but nothing regarding TWAIN.

My goal would be to add that force close in the installation script so it makes SURE that WIA or TWAIN cannot be in use whatsoever before installing.


Solution

  • I found the solution, might be useful for any other people having problems with these drivers. First download ListDlls by SysInternals : https://learn.microsoft.com/en-us/sysinternals/downloads/listdlls

    Then with PowerShell:

    Stop-Service -Name stisvc -Force
    
    [string]$twain_utilise = C:\TEMP\Listdlls.exe -d TwainDSM.dll | select-string "pid"
    
    if ($twain_utilise) {
    $processus = ($twain_utilise -Split(": "))[1]
    } 
    
    Stop-Process -id $processus -Force
    

    Explanation :

    -Stop the service STISVC which is in charge of WIA (Windows Image Acquisition (WIA))

    -Run ListDlls.exe on TWAINDSM.DLL to find out what is using the dll by selecting the PID of found program.

    -IF the command was successful (in other terms, if the PID was found, meaning a program IS using that DLL), split the content so you can isolate the PID number only.

    -Stop the process with it's PID so TWAIN isn't in use anymore

    You now have stopped any use of WIA or TWAIN and can proceed to install drivers or software that require these drivers not to be in use! Cheers.