• ×
    Information
    Need Windows 11 help?
    Check documents on compatibility, FAQs, upgrade information and available fixes.
    Windows 11 Support Center.
  • post a message
  • ×
    Information
    Need Windows 11 help?
    Check documents on compatibility, FAQs, upgrade information and available fixes.
    Windows 11 Support Center.
  • post a message
Guidelines
We have new content about printers, Click here to check it out!
Check some of the most frequent questions about Instant Ink: HP INSTANT INK, HP+ PLANS: INK AND TONER.


Check out our WINDOWS 11 Support Center info about: OPTIMIZATION, KNOWN ISSUES, FAQs AND MORE.
HP Recommended
M477fdw
Microsoft Windows 10 (64-bit)

Can HPscan.exe take command line switches? 

None of my experiments have worked.

 

What I want to do is set up a shortcut to a particular scanning definition I have already set up, such as Save as PDF, so that the scan runs straight away. 

 

In other words what I am looking for is a shortcut that opens HP scan, selects my Save as PDF definition then 'clicks' on the Scan button.

 

Can this be done?

 

In case versions make a difference - 

my printer-scanner is M477fdw,

the HPScan dialog has the header HP CLJM477 scan driver,

the file HPScan.exe is v36.0.745.0

 

Denis

1 ACCEPTED SOLUTION

Accepted Solutions
HP Recommended

1  I set up the two scanning definitions [what the UI calls its "Scan shortcuts"] that I wanted to automate and numbered them for ease of reference in the VBS file that is described below.

HPScan UI.png

 

2  I wrote a VBS file that would run on both 32 bit and 64 bit Windows without any further adjustment.  I called it LaserJet HPScan - PDF,JPG.vbs   {Note that each If  line has been wrapped across 2 or 3 lines below so you'll need to put each If  line back into a single line to use the code so you have 2 lines beginning with If  and then the WScript.Sleep  15000 line - when joining the lines back up note they they have been split where there were spaces so make sure the spaces remain afterwards.]

 

Code layout.png

 

DefinitionNumber = WScript.Arguments.Item(0)

 

Set wShell=CreateObject("WScript.Shell")


If not left (wShell.ExpandEnvironmentStrings("%ProgramFiles(x86)%"), 1)="%" then  wShell.Run chr(34) & "C:\Program Files (x86)\HP\HP Color LaserJet Pro MFP M477\bin\HPScan.exe " & Chr(34), 5
If left (wShell.ExpandEnvironmentStrings("%ProgramFiles(x86)%"), 1)="%" then  wShell.Run chr(34) & "C:\Program Files\HP\HP Color LaserJet Pro MFP M477\bin\HPScan.exe " & Chr(34), 5

 

WScript.Sleep 15000

 

wShell.AppActivate "HP Scan"
wShell.SendKeys "{TAB 3}"
If DefinitionNumber = 1 Then wShell.SendKeys "{1}"
If DefinitionNumber = 2 Then wShell.SendKeys "{2}"
wShell.SendKeys "{TAB 13}"
wShell.SendKeys "{ENTER}"

 

3  I created two shortcuts to this file and adjusted their names & properties to match the two scanning definitions

 

3.1  I named one shortcut LaserJet HPScan - PDF  and I added a space then a 1 at the end of its Target property

LaserJet HPScan - PDF.png

 

 

3.2  I named the other shortcut LaserJet HPScan - JPG  and I added a space then a 2 at the end of its Target property

LaserJet HPScan - JPG.png

 

I can now click on the shortcut I want and HPScan will open, scan and save without any further action on my part.

 

4  Refinements

4.1  I set specific icons for the shortcuts by using the Change icon button shown above - I chose a scanner icon for the PDF shortcut and a picture icon for the JPG shortcut.  Both these icons were in the standard set that appears when using the Change icon button.  

4.2  I created a pinnable version of the PDF shortcut and pinned it to my Taskbar.  All I had to do was insert WScript.exe  then a space in front of the existing shortcut Target property.

Pinnable shortcut.png

 

4.3  I timed each of my computers and increased the pausing time [WScript.Sleep 15000] to 25000 on the oldest one because it was not always ready in time.  The numbers are MilliSeconds.  I inserted lines in the VBS to detect the ComputerName then set the Sleep time to 3000, 15000, 25000 for the three computers I use based purely on trying it and seeing how long they took to be ready to receive the wShell.SendKeys lines that follow the sleep line.

 

4.4  I also played around with automating HPScan completely so that a shortcut opened it, scanned, saved then closed but it proved to be unreliable.  VBS is not very good at controlling applications because reaction times can vary depending on computer speed and loading.

 

I hope this helps somebody,

 

Denis

View solution in original post

1 REPLY 1
HP Recommended

1  I set up the two scanning definitions [what the UI calls its "Scan shortcuts"] that I wanted to automate and numbered them for ease of reference in the VBS file that is described below.

HPScan UI.png

 

2  I wrote a VBS file that would run on both 32 bit and 64 bit Windows without any further adjustment.  I called it LaserJet HPScan - PDF,JPG.vbs   {Note that each If  line has been wrapped across 2 or 3 lines below so you'll need to put each If  line back into a single line to use the code so you have 2 lines beginning with If  and then the WScript.Sleep  15000 line - when joining the lines back up note they they have been split where there were spaces so make sure the spaces remain afterwards.]

 

Code layout.png

 

DefinitionNumber = WScript.Arguments.Item(0)

 

Set wShell=CreateObject("WScript.Shell")


If not left (wShell.ExpandEnvironmentStrings("%ProgramFiles(x86)%"), 1)="%" then  wShell.Run chr(34) & "C:\Program Files (x86)\HP\HP Color LaserJet Pro MFP M477\bin\HPScan.exe " & Chr(34), 5
If left (wShell.ExpandEnvironmentStrings("%ProgramFiles(x86)%"), 1)="%" then  wShell.Run chr(34) & "C:\Program Files\HP\HP Color LaserJet Pro MFP M477\bin\HPScan.exe " & Chr(34), 5

 

WScript.Sleep 15000

 

wShell.AppActivate "HP Scan"
wShell.SendKeys "{TAB 3}"
If DefinitionNumber = 1 Then wShell.SendKeys "{1}"
If DefinitionNumber = 2 Then wShell.SendKeys "{2}"
wShell.SendKeys "{TAB 13}"
wShell.SendKeys "{ENTER}"

 

3  I created two shortcuts to this file and adjusted their names & properties to match the two scanning definitions

 

3.1  I named one shortcut LaserJet HPScan - PDF  and I added a space then a 1 at the end of its Target property

LaserJet HPScan - PDF.png

 

 

3.2  I named the other shortcut LaserJet HPScan - JPG  and I added a space then a 2 at the end of its Target property

LaserJet HPScan - JPG.png

 

I can now click on the shortcut I want and HPScan will open, scan and save without any further action on my part.

 

4  Refinements

4.1  I set specific icons for the shortcuts by using the Change icon button shown above - I chose a scanner icon for the PDF shortcut and a picture icon for the JPG shortcut.  Both these icons were in the standard set that appears when using the Change icon button.  

4.2  I created a pinnable version of the PDF shortcut and pinned it to my Taskbar.  All I had to do was insert WScript.exe  then a space in front of the existing shortcut Target property.

Pinnable shortcut.png

 

4.3  I timed each of my computers and increased the pausing time [WScript.Sleep 15000] to 25000 on the oldest one because it was not always ready in time.  The numbers are MilliSeconds.  I inserted lines in the VBS to detect the ComputerName then set the Sleep time to 3000, 15000, 25000 for the three computers I use based purely on trying it and seeing how long they took to be ready to receive the wShell.SendKeys lines that follow the sleep line.

 

4.4  I also played around with automating HPScan completely so that a shortcut opened it, scanned, saved then closed but it proved to be unreliable.  VBS is not very good at controlling applications because reaction times can vary depending on computer speed and loading.

 

I hope this helps somebody,

 

Denis

† The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the <a href="https://www8.hp.com/us/en/terms-of-use.html" class="udrlinesmall">Terms of Use</a> and <a href="/t5/custom/page/page-id/hp.rulespage" class="udrlinesmall"> Rules of Participation</a>.