MSFN Forum: The best way to set the default printer via commandline, or in a batch - MSFN Forum

Jump to content


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

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

#1 User is offline   clivebuckwheat 

  • Senior Member
  • PipPipPipPip
  • Group: Members
  • Posts: 562
  • Joined: 07-November 05

Posted 03 August 2010 - 07:12 PM

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?


#2 User is offline   cluberti 

  • Gustatus similis pullus
  • Group: Supervisor
  • Posts: 11,219
  • Joined: 09-September 01
  • OS:Windows RT
  • Country: Country Flag

Posted 03 August 2010 - 08:54 PM

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.

#3 User is offline   clivebuckwheat 

  • Senior Member
  • PipPipPipPip
  • Group: Members
  • Posts: 562
  • Joined: 07-November 05

Posted 03 August 2010 - 10:04 PM

The printers are already installed, I just have to set the right default printer. Hopefully this scripts can do it.

View Postcluberti, on 03 August 2010 - 08:54 PM, said:

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 User is offline   cluberti 

  • Gustatus similis pullus
  • Group: Supervisor
  • Posts: 11,219
  • Joined: 09-September 01
  • OS:Windows RT
  • Country: Country Flag

Posted 03 August 2010 - 10:52 PM

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

#5 User is offline   clivebuckwheat 

  • Senior Member
  • PipPipPipPip
  • Group: Members
  • Posts: 562
  • Joined: 07-November 05

Posted 04 August 2010 - 07:08 AM

View Postcluberti, on 03 August 2010 - 10:52 PM, said:

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.

This post has been edited by clivebuckwheat: 04 August 2010 - 07:10 AM


#6 User is offline   cluberti 

  • Gustatus similis pullus
  • Group: Supervisor
  • Posts: 11,219
  • Joined: 09-September 01
  • OS:Windows RT
  • Country: Country Flag

Posted 04 August 2010 - 07:47 AM

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.

#7 User is offline   clivebuckwheat 

  • Senior Member
  • PipPipPipPip
  • Group: Members
  • Posts: 562
  • Joined: 07-November 05

Posted 04 August 2010 - 07:08 PM

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!







View Postcluberti, on 04 August 2010 - 07:47 AM, said:

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 User is offline   cluberti 

  • Gustatus similis pullus
  • Group: Supervisor
  • Posts: 11,219
  • Joined: 09-September 01
  • OS:Windows RT
  • Country: Country Flag

Posted 04 August 2010 - 10:41 PM

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

#9 User is offline   clivebuckwheat 

  • Senior Member
  • PipPipPipPip
  • Group: Members
  • Posts: 562
  • Joined: 07-November 05

Posted 04 August 2010 - 11:39 PM

The connection does exists in ports under printers. I am looking at it as I type this.


View Postcluberti, on 04 August 2010 - 10:41 PM, said:

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 User is offline   cluberti 

  • Gustatus similis pullus
  • Group: Supervisor
  • Posts: 11,219
  • Joined: 09-September 01
  • OS:Windows RT
  • Country: Country Flag

Posted 05 August 2010 - 12:30 AM

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


#11 User is offline   clivebuckwheat 

  • Senior Member
  • PipPipPipPip
  • Group: Members
  • Posts: 562
  • Joined: 07-November 05

Posted 05 August 2010 - 06:48 AM

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

I will give it a shot.


View Postcluberti, on 05 August 2010 - 12:30 AM, said:

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 User is offline   clivebuckwheat 

  • Senior Member
  • PipPipPipPip
  • Group: Members
  • Posts: 562
  • Joined: 07-November 05

Posted 05 August 2010 - 02:40 PM

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.

View Postclivebuckwheat, on 05 August 2010 - 06:48 AM, said:

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

I will give it a shot.


View Postcluberti, on 05 August 2010 - 12:30 AM, said:

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 User is offline   cluberti 

  • Gustatus similis pullus
  • Group: Supervisor
  • Posts: 11,219
  • Joined: 09-September 01
  • OS:Windows RT
  • Country: Country Flag

Posted 05 August 2010 - 06:25 PM

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.

#14 User is offline   clivebuckwheat 

  • Senior Member
  • PipPipPipPip
  • Group: Members
  • Posts: 562
  • Joined: 07-November 05

Posted 05 August 2010 - 10:37 PM

I found a work around, is there a way to turn of the windows scripting confirmation box, on the fly?


View Postcluberti, on 05 August 2010 - 06:25 PM, said:

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 User is offline   cluberti 

  • Gustatus similis pullus
  • Group: Supervisor
  • Posts: 11,219
  • Joined: 09-September 01
  • OS:Windows RT
  • Country: Country Flag

Posted 06 August 2010 - 02:02 PM

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

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2013 msfn.org
Privacy Policy