Sunday, August 19, 2018

Powershell TWAIN / scan from USB

This is just me being lazy, really...
  1. Plug in USB scanner...
  2. Start Button
  3. Open the 'Devices and Printers' applet
  4. Find the scanner
  5. Right-Click, and 'Start a Scan'

Or -
Write something that will find the scanner, and open the 'Start a Scan' window, when the script is ran...


I enabled the Quick Launch bar, and have this in there as a shortcut - I just changed the icon to a 'scanner'. (from here: %SystemRoot%\System32\SHELL32.dll)


This is the command for the shortcut...
Target:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe –NoProfile -windowstyle hidden -file "C:\Users\Rich\PSScripts\StartScan.ps1"

This line can be ran, to discover the 'Device description' for your device...
(gwmi Win32_USBControllerDevice |%{[wmi]($_.Dependent)}).Description

Here is the scripts text:
$DeviceDesc = "CanoScan"
$FindTWAIN = (gwmi Win32_USBControllerDevice |%{[wmi]($_.Dependent)} | Where-Object {($_.Description  -match $DeviceDesc)})
If ($FindTWAIN.Name -match $DeviceDesc){
$DeviceID = ($FindTWAIN.DeviceID).Replace("\","#")
$ClassGuid = $FindTWAIN.ClassGuid
$FullCommand = "`"C:\WINDOWS\system32\rundll32.exe`" fdprint,InvokeTask /ss `"\\?\"
$Params = "`"\\?\"+$DeviceID+"#"+$ClassGuid+"`""
& "C:\WINDOWS\system32\rundll32.exe" fdprint,InvokeTask /ss $Params
}

If ($FindTWAIN.Name -Notmatch $DeviceDesc){
#######################
$MsgBoxInfo = "$DeviceDesc device not found..."
[void] [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.VisualBasic")
[Microsoft.VisualBasic.Interaction]::MsgBox($MsgBoxInfo, "OKOnly,SystemModal,Exclamation", "Nothing Found.") | Out-null
 ## Out-null just supresses the 'ok' to the (ISE?) screen, after pressing the OK button.
#######################
}

5 comments:

  1. Nice,
    Any ideas on how to look at other TWAIN / WIA devices?
    Sometimes the device is connected via Ethernet / WiFi.

    ReplyDelete
    Replies
    1. Unfortunately - I don't have any such equipment to play with - So...
      No - I have no idea.

      Delete
  2. Truly accommodating Web journal simply shared much appreciated and I checked more related themes in laser scanning, reverse engineering, pointcloud. Keep updating. 3d laser scanner Denver, Colorado

    ReplyDelete
  3. First, they help them locate the best paths for telecommunications equipment via topographical surveying. Second, they help them to ensure the equipment coheres with its environment. Third, scan data can be helpful for maintenance, troubleshooting and rerouting paths of line. 3d laser scanning survey Sydney

    ReplyDelete
  4. Free Recuva Download Full Version Howdy, I see as cognizant part concentrating on this text a delight. it's miles really pleasurable to prepared and fascinating and profoundly tons looking take care of to perusing extra of your trademark..

    ReplyDelete