Sign in to follow this  
Followers 0
clivebuckwheat

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

15 posts in this topic

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?

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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).

0

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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.qc.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.

0

Share this post


Link to post
Share on other sites

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).

0

Share this post


Link to post
Share on other sites

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).

0

Share this post


Link to post
Share on other sites

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 & "'")

0

Share this post


Link to post
Share on other sites

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 & "'")

0

Share this post


Link to post
Share on other sites

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 & "'")

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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..... ;)).

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.