Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account



Photo

The best way to set the default printer via commandline, or in a batch


  • Please log in to reply
14 replies to this topic

#1
clivebuckwheat

clivebuckwheat

    Senior Member

  • Member
  • PipPipPipPip
  • 577 posts
  • Joined 07-November 05
Is this still valid?

rundll32 printui.dll,PrintUIEntry /y /q /n “Printer name”

also how can I disable UAC on the fly again via batch or command line?


How to remove advertisement from MSFN

#2
cluberti

cluberti

    Gustatus similis pullus

  • Supervisor
  • 11,252 posts
  • Joined 09-September 01
  • OS:Windows 8.1 x64
  • Country: Country Flag
If you're using Vista or Win7, look in the \System32 folder for the Printing_Admin_Scripts folder. There are vbs scripts there to do printer management, so you no longer have to use rundll32 to install drivers, queues, etc.
MCTS Windows Internals, MCITP Server 2008 EA, MCTS MDT/BDD, MCSE/MCSA Server 2003, Server 2012, Windows 8
--------------------
Please read the rules before posting!
Please consider donating to MSFN to keep it up and running!

#3
clivebuckwheat

clivebuckwheat

    Senior Member

  • Member
  • PipPipPipPip
  • 577 posts
  • Joined 07-November 05
The printers are already installed, I just have to set the right default printer. Hopefully this scripts can do it.

If you're using Vista or Win7, look in the \System32 folder for the Printing_Admin_Scripts folder. There are vbs scripts there to do printer management, so you no longer have to use rundll32 to install drivers, queues, etc.



#4
cluberti

cluberti

    Gustatus similis pullus

  • Supervisor
  • 11,252 posts
  • Joined 09-September 01
  • OS:Windows 8.1 x64
  • Country: Country Flag
From prnmngr.vbs:
'----------------------------------------------------------------------
'
' Copyright (c) Microsoft Corporation. All rights reserved.
'
' Abstract:
' prnmngr.vbs - printer script for WMI on Windows 
'     used to add, delete, and list printers and connections
'     also for getting and setting the default printer
'
' Usage:
' prnmngr [-adxgtl?][co] [-s server][-p printer][-m driver model][-r port]
'                       [-u user name][-w password]
'
' Examples:
' prnmngr -a -p "printer" -m "driver" -r "lpt1:"
' prnmngr -d -p "printer" -s server
' prnmngr -ac -p "\\server\printer"
' prnmngr -d -p "\\server\printer"
' prnmngr -x -s server
' prnmngr -l -s server
' prnmngr -g
' prnmngr -t -p "printer"
'
'----------------------------------------------------------------------
You would use -t -p "printer" to set the default printer by it's common name (use -g to get the current default to see what I mean).
MCTS Windows Internals, MCITP Server 2008 EA, MCTS MDT/BDD, MCSE/MCSA Server 2003, Server 2012, Windows 8
--------------------
Please read the rules before posting!
Please consider donating to MSFN to keep it up and running!

#5
clivebuckwheat

clivebuckwheat

    Senior Member

  • Member
  • PipPipPipPip
  • 577 posts
  • Joined 07-November 05

From prnmngr.vbs:

'----------------------------------------------------------------------
'
' Copyright (c) Microsoft Corporation. All rights reserved.
'
' Abstract:
' prnmngr.vbs - printer script for WMI on Windows 
'     used to add, delete, and list printers and connections
'     also for getting and setting the default printer
'
' Usage:
' prnmngr [-adxgtl?][co] [-s server][-p printer][-m driver model][-r port]
'                       [-u user name][-w password]
'
' Examples:
' prnmngr -a -p "printer" -m "driver" -r "lpt1:"
' prnmngr -d -p "printer" -s server
' prnmngr -ac -p "\\server\printer"
' prnmngr -d -p "\\server\printer"
' prnmngr -x -s server
' prnmngr -l -s server
' prnmngr -g
' prnmngr -t -p "printer"
'
'----------------------------------------------------------------------
You would use -t -p "printer" to set the default printer by it's common name (use -g to get the current default to see what I mean).


Thank you sir,I have learned so much from this place. would you know how to turn off uac it is bothersome.

Edited by clivebuckwheat, 04 August 2010 - 07:10 AM.


#6
cluberti

cluberti

    Gustatus similis pullus

  • Supervisor
  • 11,252 posts
  • Joined 09-September 01
  • OS:Windows 8.1 x64
  • Country: Country Flag
If it's just for your own machine, you can modify the EnableLUA reg value via the command:
reg ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0 /f

However, if this is in any sort of domain environment (where UAC for non-admin users is actually preferable), you can make a local (or group) policy change so that Admins don't get prompted under Computer Configuration > Windows Settings > Local Policies > Security Options > User Account Control: Behavior of the elevation prompt for administrators in Admin Approval Mode - set this to "Elevate without prompting". Note that this can also be done by direct modification of the ConsentPromptBehaviorAdmin reg value via the command:
reg ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v ConsentPromptBehaviorAdmin /t REG_DWORD /d 0 /f

In a domain environment you would want to do this from a policy rather than a registry tatoo, but it is possible to edit the registry to mimick this policy.
MCTS Windows Internals, MCITP Server 2008 EA, MCTS MDT/BDD, MCSE/MCSA Server 2003, Server 2012, Windows 8
--------------------
Please read the rules before posting!
Please consider donating to MSFN to keep it up and running!

#7
clivebuckwheat

clivebuckwheat

    Senior Member

  • Member
  • PipPipPipPip
  • 577 posts
  • Joined 07-November 05
I am trying to use the vbs scripts built into Windows 7 you pointed me to.

here is the syntax I am using

cscript.exe "C:\Windows\System32\Printing_Admin_Scripts\en-US\Prnmngr.vbs" -t -p "http://myprintserver....ca/ipps/2F16P"

I keep getting this error

C:\Windows\System32\Printing_Admin_Scripts\en-US\Prnmngr.vbs(818, 9) SWbemServic esEx: Not found

HELP!







If it's just for your own machine, you can modify the EnableLUA reg value via the command:
reg ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0 /f

However, if this is in any sort of domain environment (where UAC for non-admin users is actually preferable), you can make a local (or group) policy change so that Admins don't get prompted under Computer Configuration > Windows Settings > Local Policies > Security Options > User Account Control: Behavior of the elevation prompt for administrators in Admin Approval Mode - set this to "Elevate without prompting". Note that this can also be done by direct modification of the ConsentPromptBehaviorAdmin reg value via the command:
reg ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v ConsentPromptBehaviorAdmin /t REG_DWORD /d 0 /f

In a domain environment you would want to do this from a policy rather than a registry tatoo, but it is possible to edit the registry to mimick this policy.



#8
cluberti

cluberti

    Gustatus similis pullus

  • Supervisor
  • 11,252 posts
  • Joined 09-September 01
  • OS:Windows 8.1 x64
  • Country: Country Flag
That printer name looks awfully wrong - I think you're trying to set a default printer with a connection you haven't created. Look deeper into the -ac and -p options (run the script with no switches to get an idea of what you're doing wrong).
MCTS Windows Internals, MCITP Server 2008 EA, MCTS MDT/BDD, MCSE/MCSA Server 2003, Server 2012, Windows 8
--------------------
Please read the rules before posting!
Please consider donating to MSFN to keep it up and running!

#9
clivebuckwheat

clivebuckwheat

    Senior Member

  • Member
  • PipPipPipPip
  • 577 posts
  • Joined 07-November 05
The connection does exists in ports under printers. I am looking at it as I type this.


That printer name looks awfully wrong - I think you're trying to set a default printer with a connection you haven't created. Look deeper into the -ac and -p options (run the script with no switches to get an idea of what you're doing wrong).



#10
cluberti

cluberti

    Gustatus similis pullus

  • Supervisor
  • 11,252 posts
  • Joined 09-September 01
  • OS:Windows 8.1 x64
  • Country: Country Flag
Is that an actual printer name though? Try running this as a .vbs, and see what deviceIDs you have on that box (again, assuming that port and printer is already added):
strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_Printer",,48) 
For Each objItem in colItems 
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "Win32_Printer instance"
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "DeviceID: " & objItem.DeviceID
Next
It's saying the object's DeviceID is not found - this is the line that's failing:
set oPrinter = oService.Get("Win32_Printer.DeviceID='" & strPrinter & "'")

MCTS Windows Internals, MCITP Server 2008 EA, MCTS MDT/BDD, MCSE/MCSA Server 2003, Server 2012, Windows 8
--------------------
Please read the rules before posting!
Please consider donating to MSFN to keep it up and running!

#11
clivebuckwheat

clivebuckwheat

    Senior Member

  • Member
  • PipPipPipPip
  • 577 posts
  • Joined 07-November 05
The printer looks wrong because it's Novell using ipp printing,

I will give it a shot.


Is that an actual printer name though? Try running this as a .vbs, and see what deviceIDs you have on that box (again, assuming that port and printer is already added):

strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_Printer",,48) 
For Each objItem in colItems 
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "Win32_Printer instance"
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "DeviceID: " & objItem.DeviceID
Next
It's saying the object's DeviceID is not found - this is the line that's failing:
set oPrinter = oService.Get("Win32_Printer.DeviceID='" & strPrinter & "'")



#12
clivebuckwheat

clivebuckwheat

    Senior Member

  • Member
  • PipPipPipPip
  • 577 posts
  • Joined 07-November 05
Cluberti, thanks man that script gave me the proper path name of the printer. The default printer, and a printer deletion works now.

Is there a way to run a cmd file with elevated privileges or as administrator?. I am running a cmd file from a login script.

The printer looks wrong because it's Novell using ipp printing,

I will give it a shot.



Is that an actual printer name though? Try running this as a .vbs, and see what deviceIDs you have on that box (again, assuming that port and printer is already added):

strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_Printer",,48) 
For Each objItem in colItems 
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "Win32_Printer instance"
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "DeviceID: " & objItem.DeviceID
Next
It's saying the object's DeviceID is not found - this is the line that's failing:
set oPrinter = oService.Get("Win32_Printer.DeviceID='" & strPrinter & "'")



#13
cluberti

cluberti

    Gustatus similis pullus

  • Supervisor
  • 11,252 posts
  • Joined 09-September 01
  • OS:Windows 8.1 x64
  • Country: Country Flag
The runas command should be able to do this, although if the user is not an administrator they'll likely see a consent prompt unless you change the default behavior in policy.
MCTS Windows Internals, MCITP Server 2008 EA, MCTS MDT/BDD, MCSE/MCSA Server 2003, Server 2012, Windows 8
--------------------
Please read the rules before posting!
Please consider donating to MSFN to keep it up and running!

#14
clivebuckwheat

clivebuckwheat

    Senior Member

  • Member
  • PipPipPipPip
  • 577 posts
  • Joined 07-November 05
I found a work around, is there a way to turn of the windows scripting confirmation box, on the fly?


The runas command should be able to do this, although if the user is not an administrator they'll likely see a consent prompt unless you change the default behavior in policy.



#15
cluberti

cluberti

    Gustatus similis pullus

  • Supervisor
  • 11,252 posts
  • Joined 09-September 01
  • OS:Windows 8.1 x64
  • Country: Country Flag
Are you talking about the UAC prompt dialog? If so, the answer is no (imagine the security hole if you could dismiss the box from script..... ;)).
MCTS Windows Internals, MCITP Server 2008 EA, MCTS MDT/BDD, MCSE/MCSA Server 2003, Server 2012, Windows 8
--------------------
Please read the rules before posting!
Please consider donating to MSFN to keep it up and running!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users