Search This Blog

Wednesday, September 02, 2015

Map remote printer

map a local printer to TS session when "bring local printers to TS" fails miserably and start the App only after the printer is available

@echo off
setlocal enableextensions enabledelayedexpansion
set result=0
ser printer=oj100
Title Adding Printer. Be patient...
echo Adding printer. Do not start App yet...
ping -n 2 >nul 2>nul
taskkill /fi "username eq %username%" /im app.exe 2>nul
ping -n 2 >nul 2>nul
echo Please wait. Starting Installation...
echo ..
for /F "tokens=2 delims=/: " %%f in ('%userprofile%\gettscip.exe') do (
echo Your IP is: %%f
net use \\%%f\ipc$ /d /y >nul 2>nul
ping -n 1 >nul 2>nul
net use \\%%f\ipc$ && set result=1
echo Result: !result!
if not !result! equ 1 goto :loop
Echo Add printer. This is going to take up to 5 minutes, be patient...
rundll32 printui.dll,PrintUIEntry /in /n "\\%%f\!printer!" /u /q /Gw
echo Setting default printer...
rundll32 printui.dll,PrintUIEntry /y /n  "\\%%f\!printer!" /q
Echo Starting App...
ping -n 3 >nul 2>nul
taskkill /fi "username eq %username%" /im app.exe >nul 2>nul

No comments:

Post a Comment

Blog Archive