-
Notifications
You must be signed in to change notification settings - Fork 0
/
prnmgr.bat
49 lines (42 loc) · 2.08 KB
/
prnmgr.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
@echo off
echo YOU DID NOT EDIT THE SCRIPT. YOU MUST REMOVE THIS BEFORE THIS SCRIPT WILL WORK.
echo Exiting.
wait 10
exit
chcp 65001
: BatchGotAdmin
:-------------------------------------
REM --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges...
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "cmd.exe", "/C """"%~f0""""", , "runas", 1 >> "%temp%\getadmin.vbs"
cscript "%temp%\getadmin.vbs"
exit /B
:gotAdmin
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
pushd "%CD%"
CD /D "%~dp0"
rem --- ADMIN RIGHTS REQUIRED FOR BELOW CONFIGURATION ---
Echo WE ARE NOW STARTING PRINTER CONFIGURATION. PLEASE STAND BY.
Echo ===============================Deleting Existing Printers
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -x
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -xc
Echo ===============================Deleting Existing Ports
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -d -s \\%computername% -r <if you know your existing port> | cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -d -s \\%computername% -r WSD*
Echo ===============================Deleting Existing Drivers
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs -x
Echo ===============================Adding new Printer
powershell.exe -ExecutionPolicy Bypass -Command "echo <The Name You Want Your Users To See> | Add-Printer -DeviceURL <Add Device URL>"
echo ===============================Setting new Printer as Default
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -s \\%computername% -t -p <The Name You Want Your Users To See>
Echo ===============================Rebooting and removing script
echo WE ARE NOW REBOOTING. PLEASE STAND BY.
shutdown.exe /r /t 10
del "%~f0"
rem --- END OF BATCH ----