Register PC on Brother Scanner

A client reported that his PC was disappearing from the Scan to PC list on his Brother 7065 multi-function device every day, apparently after logging off. When he logged on again, if he would do a manual scan from his PC, the computer would be listed again.

Brother support said that the scanner looks for available PCs when you press the Scan to button, and advised me to confirm firewall exceptions as outlined in this article. The default exception (UDP 54925) was in fact out of date—it was created on the Private profile but the computer had since joined the domain. I added a group policy to create exceptions on UDP 137, 54925, and 54926:

Brother Scanner 0

Still the scanner could not see the computer. Even with the firewall turned off, pressing the Scan to button did not find the PC. Apparently the scanner does not search for PCs, so the PC must somehow be registering with the scanner.

You would think that running Brother ControlCenter4 would be enough to register the PC with the scanner, but it is not, at least not always, whether run in the foreground or at PC startup (in the background). You have to actually initiate a scan from the computer for the computer to register with the scanner. Very inconvenient if you log off your computer every night.

Wireshark Sniffing

Finally I fired up the Wireshark packet sniffer to see how the computer and scanner talk to each other. I was a little surprised to find out that it is via SNMP. And the key line is an SNMP set-request command that tells the scanner the name and IP address of the computer.

Brother Scanner 1

By digging into the network packet I was able to dig out the OID and the “payload”:

1.3.6.1.4.1.2435.2.3.9.2.11.1.1.0

TYPE=BR;BUTTON=SCAN;USER=”MYPC”;FUNC=IMAGE;HOST=192.168.1.11:54925;APPNUM=1;DURATION=360;
TYPE=BR;BUTTON=SCAN;USER=”MYPC”;FUNC=OCR;HOST=192.168.1.11:54925;APPNUM=3;DURATION=360;
TYPE=BR;BUTTON=SCAN;USER=”MYPC”;FUNC=EMAIL;HOST=192.168.1.11:54925;APPNUM=2;DURATION=360;
TYPE=BR;BUTTON=SCAN;USER=”MYPC”;FUNC=FILE;HOST=192.168.1.11:54925;APPNUM=5;DURATION=360;

where USER is the name of my PC and HOST is my PC’s IP address.

Googling the OID led to some helpful articles like this one about people trying to set this e.g. for Linux drivers. I decided to try a similar approach:  create a batch file to call an snmpset command at each user logon.

Caveats This has been tested with Brother 7065 and and 8810 multi-function devices. The SNMP commands were the same for these two devices but you may need to adjust them for yours. As always, use code and scripts at your own risk!

Step 1:  Install Net-SNMP

The batch file relies on an open-source package called Net-SNMP. I used 32-bit version 5.6.1.1. Download it here. This is actually a large array of SNMP utilities. The snmpset.exe program has file and path dependencies, so just install the whole package on the local PCs and put it in the default path C:\usr. Ignore warnings about 32-bit on 64-bit and about the length of your Path. You do not need the agents or other components so uncheck them:

Brother Scanner 2

Step 2:  Deploy the Batch File

Copy the batch file from the end of this article to a file, e.g. RegisterPCOnBrotherScanner.cmd.

If you want to run it manually, at a command prompt, just type the command name followed by the IP address of your scanner:

RegisterPCOnBrotherScanner.cmd 192.168.1.15

Script output is saved to this file:

%LocalAppData%\BrotherScanner\RegisterPCOnBrotherScanner.log

Deploy Using Group Policy

To deploy the script using Group Policy, on the domain controller:

1. Create a new group policy that applies to the PCs that need this script.

2. Get the ID of the policy and copy the script to its User\Scripts\Logon folder, e.g.

C:\Windows\SYSVOL\domain\Policies\{33EF2A7C-B70A-4E24-9BD8-787640261AF0}\User\Scripts\Logon

3. Edit the group policy. Add the script under User Configuration > Windows Settings > Scripts > Logon. providing the IP address of your scanner as the parameter:

Brother Scanner 3

4. On a local machine, run gpupdate to apply the group policy, log off, and log on. Check this file to confirm that it ran successfully:

%LocalAppData%\BrotherScanner\RegisterPCOnBrotherScanner.log

Check the scanner to confirm that the PC appears in the Scan to PC list.

The Script

Here is the script. Copy and paste to a file, e.g. RegisterPCOnBrotherScanner.cmd:

@echo off
REM Use Net-SNMP to register this PC on the Brother scanner specified in the parameter.
REM The machine is registered for IMAGE, OCR, EMAIL, and FILE scanning.
REM
REM Copyright 2014 by Mark Berry, MCB Systems, www.mcbsys.com.  
REM Free for personal or commercial use.  May not be sold.
REM No warranties.  Use at your own risk.
REM
REM 11/07/2014  Initial release
REM
REM Param 1:  IP address of Brother scanner.
REM
REM Prerequisites:  Assumes Net-SNMP is installed in the default C:\usr path.
REM                 Tested with Net-SNMP 5.6.1.1.  Download from
REM                 http://sourceforge.net/projects/net-snmp/files/net-snmp%20binaries/.
REM
REM 12/15/2014  Fix how %exitcode% is set.

REM ===========================================================================================
REM Set up variables
REM ===========================================================================================
REM ===========================================================================================
REM Save script path and name
REM ===========================================================================================

REM %0 is the name of the batch file.
REM ~dp gives you the drive and path of the specified argument, with trailing \.
REM ~nx gives you the filename and extension only.
REM Combine to get full path
set ScriptFullPath=%~dp0%~nx0

set ProgramPath=C:\usr\bin
set ProgramExe=snmpset.exe
REM Exit with 0; exceptions below
set /A exitcode=0

REM ===========================================================================================
REM Check for parameters
REM ===========================================================================================
if ###%1###==###### goto NoParam
goto ParamsFound

:NoParam
echo.
echo Missing parameter(s)
echo.
echo Usage:  RegisterPCOnBrotherScanner.cmd [Scanner IP address]
echo.
echo         Example:
echo.
echo         RegisterPCOnBrotherScanner.cmd 192.168.1.15
echo.
set /A exitcode=1001
goto End

:ParamsFound
REM ===========================================================================================
REM Strip quotation marks, if any, from parameters
REM ===========================================================================================
set ScannerIP=%~1

REM ===========================================================================================
REM Get local machine IP address
REM ===========================================================================================
REM See http://stackoverflow.com/a/17634009/550712
REM Note that %computername% is a standard environment variable
for /f "delims=[] tokens=2" %%a in ('ping %computername% -n 1 -4 ^| findstr "["') do (set ComputerIP=%%a)

REM ===========================================================================================
REM Set up SnmpSet parameters
REM ===========================================================================================
set ProgramParams1=-v 1 -c internal %ScannerIP% 1.3.6.1.4.1.2435.2.3.9.2.11.1.1.0 s "TYPE=BR;BUTTON=SCAN;USER=\"%ComputerName%\";FUNC=IMAGE;HOST=%ComputerIP%:54925;APPNUM=1;DURATION=360;"
set ProgramParams2=-v 1 -c internal %ScannerIP% 1.3.6.1.4.1.2435.2.3.9.2.11.1.1.0 s "TYPE=BR;BUTTON=SCAN;USER=\"%ComputerName%\";FUNC=OCR;HOST=%ComputerIP%:54925;APPNUM=3;DURATION=360;"
set ProgramParams3=-v 1 -c internal %ScannerIP% 1.3.6.1.4.1.2435.2.3.9.2.11.1.1.0 s "TYPE=BR;BUTTON=SCAN;USER=\"%ComputerName%\";FUNC=EMAIL;HOST=%ComputerIP%:54925;APPNUM=2;DURATION=360;"
set ProgramParams4=-v 1 -c internal %ScannerIP% 1.3.6.1.4.1.2435.2.3.9.2.11.1.1.0 s "TYPE=BR;BUTTON=SCAN;USER=\"%ComputerName%\";FUNC=FILE;HOST=%ComputerIP%:54925;APPNUM=5;DURATION=360;"

REM ===========================================================================================
REM Set up logging and echo date, time, and parameters
REM ===========================================================================================
if not exist "%LocalAppData%\BrotherScanner" md "%LocalAppData%\BrotherScanner"
set LogFileFullPath=%LocalAppData%\BrotherScanner\RegisterPCOnBrotherScanner.log
echo Date: %date% > %LogFileFullPath%
echo Time: %time% >> %LogFileFullPath%
echo. >> %LogFileFullPath%
echo ScriptFullPath: %ScriptFullPath% >> %LogFileFullPath%
echo    ProgramPath: %ProgramPath% >> %LogFileFullPath%
echo     ProgramExe: %ProgramExe% >> %LogFileFullPath%
echo      ScannerIP: %ScannerIP% >> %LogFileFullPath%
echo   ComputerName: %ComputerName% >> %LogFileFullPath%
echo     ComputerIP: %ComputerIP% >> %LogFileFullPath%
REM echo ProgramParams1: %ProgramParams1% >> %LogFileFullPath%
REM echo ProgramParams2: %ProgramParams2% >> %LogFileFullPath%
REM echo ProgramParams3: %ProgramParams3% >> %LogFileFullPath%
REM echo ProgramParams4: %ProgramParams4% >> %LogFileFullPath%
echo. >> %LogFileFullPath%

REM ===========================================================================================
REM Check for program path
REM ===========================================================================================
if exist "%ProgramPath%" goto PathExists
echo Program path "%ProgramPath%" does not exist. Exiting. >> %LogFileFullPath%
set /A exitcode=1002
goto End

:PathExists
REM ===========================================================================================
REM Check for program executable
REM ===========================================================================================
if exist "%ProgramPath%\%ProgramExe%" goto ProgramExists
echo Program executable "%ProgramPath%\%ProgramExe%" does not exist. Exiting. >> %LogFileFullPath%
set /A exitcode=1003
goto End

:ProgramExists
REM ===========================================================================================
REM Run ProgramExe with the specified ProgramParams1 through ProgramParams4
REM ===========================================================================================
echo Registering this computer on the Brother scanner at %ScannerIP% with these commands:>> %LogFileFullPath%
echo. >> %LogFileFullPath%

"%ProgramPath%\%ProgramExe%" %ProgramParams1% >> %LogFileFullPath%
set /a exitcode=%errorlevel%
if %exitcode% neq 0 goto End
"%ProgramPath%\%ProgramExe%" %ProgramParams2% >> %LogFileFullPath%
set /a exitcode=%errorlevel%
if %exitcode% neq 0 goto End
"%ProgramPath%\%ProgramExe%" %ProgramParams3% >> %LogFileFullPath%
set /a exitcode=%errorlevel%
if %exitcode% neq 0 goto End
"%ProgramPath%\%ProgramExe%" %ProgramParams4% >> %LogFileFullPath%
set /a exitcode=%errorlevel%
if %exitcode% neq 0 goto End

:End
exit /b %exitcode%

2 thoughts on “Register PC on Brother Scanner

  1. JC

    I understand this is a very old topic but we’ve come across this identical issue.

    The script works great, however the PC stays registered for only about 15 minutes; do you happen to know why this might be? Is there a way we can lengthen this time?

  2. Lukasz

    Well it is february 2019 and this script just works great !

Leave a Reply

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail. You can also subscribe without commenting.