DeutschEspañolFrançaisItalianoNederlandsPortuguêsΕλληνικάРусскийالعربية中文(简体)中文(繁體)日本語한국어
 
Donate Bitcoins
Google
 
www smithii.com
 

Automatically changing screen positions and default printer based upon my location

Here's my startup.cmd script I wrote to automatically change thr screen positions, and the default printer, whenever I change locations. I place this in the directory C:\WINDOWS\system32\repl\import\scripts, so it will be executed automatically when I login. It uses res_set to change the screen locations and resolutions.

@echo off

set scriptdir=%~dp0
pushd "%scriptdir%" >nul

if not "%1" == "" (set location=%1) else (set location=)

if not "%location%" == "" goto found

ipconfig | findstr "Gateway" | findstr "10\.0\.0\.1" >nul
if not errorlevel 1 set location=home

ipconfig | findstr "Gateway" | findstr "192\.168\.1\.1" >nul
if not errorlevel 1 set location=work

ipconfig | findstr "Gateway" | findstr "192\.168\.3\.1" >nul
if not errorlevel 1 set location=work2

if not "%location%" == "" goto found

echo Cannot determine location.
popd >nul
exit /b 1

:found
echo Configuring system for %location%...
goto %location%

:home
res_set -m 0 -w 1920 -h 1200 -b 32 -x 0 -y 0
res_set -m 2 -w 1920 -h 1200 -b 32 -x 0 -y -1200
cscript /nologo /b "SetDefaultPrinter.vbs" "hp LaserJet 1320 PCL 6 (home)"
goto eos

:work
res_set -m 0 -w 1920 -h 1200 -b 32 -x 0 -y 0
res_set -m 1 -w 1920 -h 1200 -b 32 -x -1920 -y -120
cscript /nologo /b "SetDefaultPrinter.vbs" "HP LaserJet 2100 PCL6 (work)"
goto eos

:work2
cscript /nologo /b "SetDefaultPrinter.vbs" "HP LaserJet 1020 (work2)"
goto eos

:eos
popd >nul
exit /b 0

Here's the SetDefaultPrinter.vbs script:

dim WshNetwork 
dim sout
dim oFS  
const StdOut = 1  
  
set oFS = CreateObject("Scripting.FileSystemObject")  
set sout = oFS.GetStandardStream(StdOut)  
sout.Write "Changing default printer to: " + Wscript.arguments.Item(0)

set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.SetDefaultPrinter Wscript.arguments.Item(0)
DeutschEspañolFrançaisItalianoNederlandsPortuguêsΕλληνικάРусскийالعربية中文(简体)中文(繁體)日本語한국어
 
Donate Bitcoins
Google
 
www smithii.com
 
Special thanks to Riester Rente Online for a generous donation!