Automatic connection of networked MFPs with scanning capabilities [Part 1]

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


I think many system administrators are known is described in the header of the MFU, they differ, first and foremost, not a very comfortable setting and that have had a bad reputation. Once, copying to another computer through a narrow channel package fullsolution for an MFP, weighing about 300 megabytes, the idea is to disassemble the installer to automate the installation got a pop-up on the eye — the work had to be suspended.



Analysis of the driver I did for about a year and a half ago, at that time, the Internet on the subject was completely empty. Now quickly googling for me now well-known keyword tools and found some scattered information. Despite this, I decided. what is collected in one place the information is still not going to bother with that in this post it is more complete.

the

Set print


First query via snmp appeared MFP HP LaserJet 1536, he decided to start. First you need to understand. it works as a printer under Windows 7; older XP dropped immediately, fresh Windows 8 in a domain, it is believed, I not see never. That's a reason to meet new PowerShell, I thought that the result was almost the main motivation in the analysis of the driver. Connect ip printer in Windows 7 consists of three stages (in Windows 8 is greatly simplified built-in cmdlets, but about it I already said — no luck), first create the ip port, then add the driver and connect the actual printer. For all of these steps, in Windows there is already a ready VBS scripts, I believe, familiar in Windows 7 path: C:\Windows\System32\Printing_Admin_Scripts\

Start with creating the port, this step is the easiest, the name of the set is 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"



It is worth noting one important feature: the printer name must be specified exactly as it is written in the inf file of the driver, for example, remove the part of the name, the script will give an error: "failed to add printer driver HP LaserJet Win32 error Code 87".

Extract the driver file with the full printer name:



It now remains to connect the printer, for this I stayed on a wonderful program printui, I advise you to look at it closer, 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 arrange all this in approximately the following script in PowerShell:

the
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("Enter the IP address of the printer.")

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

# sign & the team will switch mode and paramtre will not break
&rundll32 printui.dll,PrintUIEntry /if /b $printername /r $printersource /m $printername /u /K /q /Gw
Start-Sleep -Seconds 10
}




the

Scan


Digging in inf files of the driver to find the correct printer name and simultaneously do understand the driver structure HP, my eyes caught the following lines (in bold):

Windows Vista
[HP.NT.6.0]
"The HP LJ M1530 MFP Series Scan"= WIA_1530_Inst.NT.6.0, USB\vid_03f0&pid_012a&mi_00
"The 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]
"The HP LJ M1530 MFP Series Scan"= WIA_1530_Inst_Vista64, USB\vid_03f0&pid_012a&mi_00


Here I would like the lyrics (it would seem, at what here 1S? if you know what I mean), but drops to a dry statement: try devcon.exe.

DevCon is a program with command line interface, which is used as an alternative to device Manager it can help to enable, disable, restart, update, remove, and query individual devices or groups of devices. DevCon also provides relevant to the driver developer information that is not available with the help of the device Manager.

support.microsoft.com/kb/311272/ru

Add device ID for specifying the driver:

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

To add to the registry the required parameters, run the scan and... Bingo!
The scanner works well, left it all to draw.

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

Experimentally determined necessary for us registry keys:





For that would be helpful to add registry settings, create the file quoted below, which will serve as a template for modification inside 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_"


Finished the setup script, the scanner will look as follows:

the
$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 lies in the same directory with the script
& .\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


Patiram hands, check, modify under 1522 — working, rule victoriously under 3055 is a bummer...
The scanner does not select the tablet, the scan menu is only available in the feeder, and he refuses to scan.



the

a Serious conversation with 3055 or Man you raised on the mountain, not the rock





Here it is, the LaserJet 3055/3052 — the most harmful guy, surprisingly I see it most often. In fact — tell you a secret — I started the first went through the jungle filtering procmon output when installing the driver to search for something interesting and drowned somewhere in the middle. When once again, procmon crashed due to low memory, I decided to postpone this venture until a more friendly and calm state.

The second RAID on the analysis of MFP installer gave the result: after an hour and a half of parsing logs in the bowels of the output of the installer had found a gem hppniscan01.exe
Run with the necessary parameters instantly set the scanner device and ordered 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 is its sixty four bit, driver 3055 also only supports x86 operating systems.

The scanner driver I decided to pull from the shared folder drivers and folded separately, the necessary files are easily read from the. inf driver file. The tree turned out 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


Function installing the scanner is now quite simple, though the dependence on external components.
The final form of the script, with some sehardcore simplifications will be as follows:

the
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) {
# add other IFIs to taste
"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("Enter the IP address of the printer.")

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
# sign & before the command will switch the mode and parameters will not break
&rundll32 printui.dll,PrintUIEntry /if /b $printername /r $printersource /m $printername /u /K /q /Gw
Start-Sleep -Seconds 10

Add-Scanner $printersource $printername
}


This method is great for all around me caught MFP from HP for which I created a separate folder with the drivers and options selection in the switch function installing the scanner.

List of driver files can be viewed in sections of the. inf file [SourceDisksFiles], [RegisterDlls], [WIA_CopyFiles] and further in the file. Screenshot drivers 3055 and 1536, for clarity:



Described in this article of the code snippets it is possible to collect the full script for automatic installation of the MFP, and if you add a bit of GUI and snmp, it is possible to permanently close topic install the MFP on a new machine.

That's all for now, thank you for your attention. If the reviews will tell you what is missing MFP 3055 to work with the installation of the first method by devcon, I will be very grateful. Maybe someone is doing the same job as me, but has made great strides.

In the next part, if someone will still throw an invite in the sandbox, will show how to extend our script to work with, Xerox and Kyocera.
Article based on information from habrahabr.ru

Комментарии

Популярные сообщения из этого блога

Performance comparison of hierarchical models, Django and PostgreSQL

Transport Tycoon Deluxe / Emscripten part 2