📜 ⬆️ ⬇️

Automatic connection of network MFPs with the ability to scan [Part 1]

HP LaserJet 1522, 1536, 3052/3055, 300/400 Color ...


I think many system administrators are familiar with the ones described in the header of the MFP, they differ, first of all, by not very convenient installation and have notoriety from this. Once, copying the fullsolution package for an MFP weighing about 300 megabytes to another computer through a narrow channel, the idea of ​​disassembling this installer and automating the installation got out of sight — the work had to be suspended.



I was engaged in the analysis of the driver about a year and a half ago, while the Internet on this topic was completely empty. Now I quickly googled for the utilities keywords I now know and found some scattered information. Despite this, I decided. that the information collected in one place still does not hurt, despite the fact that in this post it is more complete.

Customize print


The first to request for snmp seemed to the HP LaserJet 1536 mfp, and decided to start with it. First you need to understand. how to connect it as a printer for Windows 7; old XP dropped immediately, fresh Windows 8 in the domain, there is an opinion I never see. That's the reason to get acquainted with the new PowerShell, I thought, which in the end was almost the main motivation in the driver's analysis. Connecting an ip-printer in Windows 7 consists of three stages (in Windows 8, everything is greatly simplified by the built-in cmdlets, but I have already said about it - no luck), first create an ip-port, then add the driver and connect the printer itself. For all these steps, there are already ready VBS scripts in Windows, and I think many people know the path to them in Windows 7: : \ Windows \ System32 \ Printing_Admin_Scripts \
')
I'll start by creating a port, this stage is the easiest, we will give the name the same as ip:
cscript C:\Windows\System32\Printing_Admin_Scripts\ru-RU\prnport.vbs -a -r "192.168.0.30" -h "192.168.0.30" -o RAW -n 9100


Add driver:
cscript C:\Windows\System32\Printing_Admin_Scripts\ru-RU\prndrvr.vbs -a -m "HP LaserJet M1530 MFP Series PCL 6" -e "Windows NT x86" -h "C:\drivers\1536\"-i "C:\drivers\1536\hpc1530c.inf"



Here it is worth noting one important feature: the printer name should be specified in the same way as it is written in the driver’s inf file, remove part of the name for the sake of example, the script will generate the error: “Could not add the HP LaserJet printer driver Win32 87 error code”.

Extract from the driver file with the full printer name:



Now it remains to connect the printer, for this I stopped at the wonderful program printui, I advise you to take a closer look at it, it has interesting keys.
&rundll32 printui.dll,PrintUIEntry /if /b "HP LaserJet M1530 MFP Series PCL 6" /r "192.168.0.30" /m "HP LaserJet M1530 MFP Series PCL 6" /u /K /q /Gw

It's time to put all this into something like the following PowerShell script:

 function Add-PrinterPort ($printersource) { cscript C:\Windows\System32\Printing_Admin_Scripts\ru-RU\prnport.vbs ` -a -r $printersource -h $printersource -o RAW -n 9100 | Out-Null } function Add-PrinterDriver ($printername, $driverpath) { $folder = Split-Path $driverPath cscript C:\Windows\System32\Printing_Admin_Scripts\ru-RU\prndrvr.vbs ` -a -m $printername -e Get-Platform -h $folder -i $driverpath } function Get-Platform { if ([System.Environment]::Is64BitOperatingSystem) { "Windows x64" } else { "Windows NT x86" } } Add-Type -As Microsoft.VisualBasic $printerSource = [Microsoft.VisualBasic.Interaction]::InputBox(" IP  .") if ($printerSource -match "^192\.168\.0\.[0-9]{1,3}$") { $printername = "HP LaserJet M1530 MFP Series PCL 6" $driverpath = "C:\drivers\1536\hpc1530c.inf" Add-PrinterPort $printersource Add-PrinterDriver $printername $driverpath #  &         &rundll32 printui.dll,PrintUIEntry /if /b $printername /r $printersource /m $printername /u /K /q /Gw Start-Sleep -Seconds 10 } 




Scanning


Delving into the inf files of the driver, in order to find the correct name of the printer and incidentally generally understanding the HP driver structure, the eye caught on the following lines (highlighted in bold):

; Windows Vista
[HP.NT.6.0]
"HP LJ M1530 MFP Series Scan" = WIA_1530_Inst.NT.6.0, USB \ vid_03f0 & pid_012a & mi_00
"HP LJ M1530 MFP Series Scan" = WIA_1530_NW.NT.6.0, vid_03f0 & pid_012a & IP_SCAN

; Windows Vista 64
[HP.NTAMD64.6.0]
"HP LJ M1530 MFP Series Scan" = WIA_1530_Inst_Vista64, USB \ vid_03f0 & pid_012a & mi_00
"HP LJ M1530 MFP Series Scan" = WIA_1530_NW_Vista64, vid_03f0 & pid_012a & IP_SCAN


I would like lyrics here (it would seem, what does 1C have to do with it? If you understand what I mean), but I’ll go down to a dry statement: try devcon.exe.

DevCon is a command-line program that is used as an alternative to the device manager. With its help, you can turn on, turn off, restart, update, delete, and poll individual devices or groups of devices. DevCon also provides information needed by the driver developer that is not available through Device Manager.

support.microsoft.com/kb/311272/en

Add a device by ID indicating the driver:

.\devcon.exe /r install C:\drivers\1536scan\hppasc16.inf "vid_03f0&pid_012a&IP_SCAN"

Add the necessary parameters to the registry, run the scan and ... Bingo!
The scanner works fine, it remains to arrange it all.

Scanner settings in the registry are stored in the following ways:
HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ Class \ {6BDD1FC6-810F-11D0-BEC7-08002BE2092F}
HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Enum \ Root \ IMAGE

We empirically determine the registry keys we need:





In order to conveniently add registry settings, create the file quoted below, which will serve as a template for modification within the script.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ Class \ {6BDD1FC6-810F-11D0-BEC7-08002BE2092F} \ _ ITEM_ \ DeviceData]
"NetworkDeviceID" = "\\ hostname: _NETWORK_NAME_.domain.local \\ ipaddr: _IP_ADDRESS _ \\ guid: \\ macaddr: _MAC_ADDRESS _ \\ port: 1"
"PortID" = "_ IP_ADDRESS_"
"NetworkHostName" = "_ NETWORK_NAME_.domain.local"
"TulipIOType" = dword: 00000005

[HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Enum \ Root \ IMAGE \ _ITEM_ \ Device Parameters]
"NetworkDeviceID" = "\\ hostname: _NETWORK_NAME_.domain.local \\ ipaddr: _IP_ADDRESS _ \\ guid: \\ macaddr: _MAC_ADDRESS _ \\ port: 1"
"PortID" = "_ IP_ADDRESS_"
"NetworkHostName" = "_ NETWORK_NAME_.domain.local"
"MAC" = "_ MAC_ADDRESS_"
"PortNumber" = "1"
"Index" = "_ ITEM_"


The finished scanner installation script will look as follows:

 $IP_ADDRESS = "192.168.0.30" $MAC_ADDRESS = "001b00b2cc00" $NETWORK_NAME = "NPI3CPOF7" $source = "C:\drivers\1536scan" $dest = Join-Path (Get-Location).path "\temporary" Copy-Item $source $dest -Recurse -Force $dest = Join-Path $dest "\hppasc16.inf" # devcon       & .\devcon.exe /r install $dest "vid_03f0&pid_012a&IP_SCAN" $item = Get-ChildItem HKLM:\SYSTEM\CurrentControlSet\Control\Class\"{6BDD1FC6-810F-11D0-BEC7-08002BE2092F}" | Select-Object -Last 1 $item = $item.Substring($item.Length-4, 4) $pattern = ".\temporary\1536.reg" $result = ".\temporary\res.reg" Get-Content $pattern | ForEach-Object { $_ -replace "_IP_ADDRESS_", $IP_ADDRESS ` -replace "_MAC_ADDRESS_", $MAC_ADDRESS ` -replace "_NETWORK_NAME_", $NETWORK_NAME ` -replace "_ITEM_", $item } | Set-Content $result & regedit /s .\temporary\res.reg 


We rub hands, we check - it works, we modify under 1522 - it works, we rule victoriously under 3055 - a bummer ...
The scanner does not allow you to select a tablet, only the feeder is available in the scan menu, and even he refuses to scan.



Serious conversation with 3055 or, Dude, you picked up the wrong stone





Here it is, the LaserJet 3055/3052 - the most harmful guy, surprisingly I see him more often than anyone. Actually - I will tell you in secret - I started working on them first - I went through the wilds of the procmon output filtering when installing the driver to search for something interesting and drowned somewhere in the middle. When the procmon fell again due to lack of memory, I decided to postpone this venture to a more friendly and calm state.

The second foray into the installer analysis of the multifunction printer gave the result: after an hour and a half of the log analysis, a pearl was found in the depths of the installer output - hppniscan01.exe
Running with the necessary parameters instantly installed the scanner in the device and registered the necessary registry branches:
hppniscan01.exe -f "hppasc16.inf" -m "vid_03f0&pid_012a&IP_SCAN" -a "192.168.0.30" -n 1




The distributions of drivers for other HP printers have its sixty-four-bit version, while the 3055 driver only supports x86 operating systems.

I decided to pull out the scanner drivers from the common folder of the drivers and fold them separately, the necessary files are easily read from the driver inf-file. The tree is the following:

C: \ Drivers \ Scanners \ ip \ 3055scan \ hpgtpusd.dll
C: \ Drivers \ Scanners \ ip \ 3055scan \ hppasc01.cat
C: \ Drivers \ Scanners \ ip \ 3055scan \ hppasc01.dll
C: \ Drivers \ Scanners \ ip \ 3055scan \ hppasc01.inf
C: \ Drivers \ Scanners \ ip \ 3055scan \ hppniscan01.exe
C: \ Drivers \ Scanners \ ip \ 3055scan \ hpptpml3.dll
C: \ Drivers \ Scanners \ ip \ 3055scan \ hpxp3390.dll
C: \ Drivers \ Scanners \ ip \ 3055scan \ Drivers \ dot4
C: \ Drivers \ Scanners \ ip \ 3055scan \ Drivers \ dot4 \ Win2000 \ hpzidr12.dll
C: \ Drivers \ Scanners \ ip \ 3055scan \ Drivers \ dot4 \ Win2000 \ hpzipm12.dll
C: \ Drivers \ Scanners \ ip \ 3055scan \ Drivers \ dot4 \ Win2000 \ hpzipr12.dll
C: \ Drivers \ Scanners \ ip \ 3055scan \ Drivers \ dot4 \ Win2000 \ hpzipr12.sys


The scanner installation function has now become quite simple, albeit with a dependency on the external component.
The final form of the script, with some hard-won simplifications, will take the following form:

 function Add-PrinterPort ($printerSource) { &cscript C:\Windows\System32\Printing_Admin_Scripts\ru-RU\prnport.vbs ` -a -r $printerSource -h $printerSource -o RAW -n 9100 | Out-Null } function Add-PrinterDriver ($printerName, $driverPath) { $folder = Split-Path $driverPath &cscript C:\Windows\System32\Printing_Admin_Scripts\ru-RU\prndrvr.vbs ` -a -m $printerName -e Get-Platform -h $folder -i $driverPath } function Get-Platform { if ([System.Environment]::Is64BitOperatingSystem) { "Windows x64" } else { "Windows NT x86" } } function Add-Scanner ($ipaddress, $printername) { switch -regex ($printername) { #      "1530" { Push-Location 'C:\Drivers\Scanners\ip\1536scan\' if ($(Get-Platform) -eq "Windows x64") { .\hppniscan64.exe -f "hppasc16.inf" -m "vid_03f0&pid_012a&IP_SCAN" -a $ipaddress -n 1 } else { .\hppniscan01.exe -f "hppasc16.inf" -m "vid_03f0&pid_012a&IP_SCAN" -a $ipaddress -n 1 } Pop-Location } "(305\d)|(3390)" { Push-Location 'C:\Drivers\Scanners\ip\3055scan\' switch -regex ($printername) { "3050" { .\hppniscan01.exe -f "hppasc01.inf" -m "vid_03f0&pid_3217&IP_SCAN" -a $ipaddress -n 1 } "3052" { .\hppniscan01.exe -f "hppasc01.inf" -m "vid_03f0&pid_3317&IP_SCAN" -a $ipaddress -n 1 } "3055" { .\hppniscan01.exe -f "hppasc01.inf" -m "vid_03f0&pid_3417&IP_SCAN" -a $ipaddress -n 1 } "3390" { .\hppniscan01.exe -f "hppasc01.inf" -m "vid_03f0&pid_3517&IP_SCAN" -a $ipaddress -n 1 } } Pop-Location } } } Add-Type -As Microsoft.VisualBasic $printerSource = [Microsoft.VisualBasic.Interaction]::InputBox(" IP  .") if ($printersource -match "^192\.168\.0\.[0-9]{1,3}$") { $printername = "HP LaserJet M1530 MFP Series PCL 6" $driverpath = "C:\drivers\1536\hpc1530c.inf" Add-PrinterPort $printersource Add-PrinterDriver $printername $driverPath #  &         &rundll32 printui.dll,PrintUIEntry /if /b $printername /r $printersource /m $printername /u /K /q /Gw Start-Sleep -Seconds 10 Add-Scanner $printersource $printername } 


The same method is great for all HP MFPs around me, for whom I created separate driver folders and options for the switch of the scanner installation function.

The list of driver files can be viewed in the inf-file sections with the names [SourceDisksFiles], [RegisterDlls], [WIA_CopyFiles] and further on. Screenshot on drivers 3055 and 1536, for clarity:



From the code snippets described in this note, you can build a full-featured automatic installation of the MFP, and if you add a little gooey and snmp to it, then you can completely close the topic of installing the MFP on new machines.

That's all for today, thank you for your attention. If the comments prompt what the MFP 3055 lacks to work with the installation using the first method via devcon, I will be very grateful. Maybe someone has done the same work as I, but has achieved great success.

In the next part, if someone throws an invite into the sandbox , I’ll show you how to expand our scenario for working with the Xerox and Kyocera multifunctional devices.

Source: https://habr.com/ru/post/242513/


All Articles