Jump to content

Set Default Printer - *Solved*


schilbiz
 Share

Recommended Posts

Hey guys I have be working on a simple script that will be executed upon login that will assign a printer share and then set it as default printer. This is what I have so far but I am having problems finding what to use to set the printer as default. Can this only be done by directly editing the registry or is there some _SetDefaultPrinter function that I am unaware of.

*The second part is kinda wishful thinking I think.

; Assign print share to current computer.
$WshNetwork =  ObjCreate("WScript.Network")
$WshNetwork.AddWindowsPrinterConnection ("\\server\hp5600")

;Wishful thinking? - Set printer to Default.
Func SetDefault($Printer)
Run(@ComSpec & " /c RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n " & $hp5600 , "",@SW_HIDE)
EndFunc

I found many interesting posts about this topic but most of them were way over my head. Bear with me please I am an AutoIt noob; thanks for the help.

Edit: Added Solved In Topic Header.

Edited by schilbiz
Link to comment
Share on other sites

; Assign print share to current computer.
$WshNetwork =  ObjCreate("WScript.Network")
$WshNetwork.AddWindowsPrinterConnection ("\\server\hp5600")

;Wishful thinking? - Set printer to Default.
Func SetDefault($Printer)
Run(@ComSpec & " /c RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n " & $hp5600 , "",@SW_HIDE)
EndFunc
I don't know what is the value of $hp5600, I'm assuming it will be \\server\hp5600. I use Rundll32 in my NetPrinter script below on my signature.

I notice you create a function SetDefault($Printer), but you are using $hp5600 in stead of $Printer. If you didn't declared $hp5600 as a GLOBAL varibale when you try to use SetDefault() function $hp5600 will be NUL.

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

; Assign print share to current computer.
$WshNetwork =  ObjCreate("WScript.Network")
$WshNetwork.AddWindowsPrinterConnection ("\\server\hp5600")

;Wishful thinking? - Set printer to Default.
Func SetDefault($Printer)
Run(@ComSpec & " /c RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n " & $hp5600 , "",@SW_HIDE)
EndFunc
I don't know what is the value of $hp5600, I'm assuming it will be \\server\hp5600. I use Rundll32 in my NetPrinter script below on my signature.

I notice you create a function SetDefault($Printer), but you are using $hp5600 in stead of $Printer. If you didn't declared $hp5600 as a GLOBAL varibale when you try to use SetDefault() function $hp5600 will be NUL.

Oops your right, that was a mistake, I was trying different things and that is what was last in there.

I have tried to use \\server\hp5600, as well as other parameters but it errs on the \\. I did trying changing $Printer to $hp5600 as well but nothing happened. It doesn't error out, it just creates the share.

Link to comment
Share on other sites

I just tested SetDefault($Printer) function in a winxp sp2, win2k sp4 and work fine setting a network and local printer as default.

As of troubleshooting I will open Printers and Faxes windows then I will open run window and paste the line below and hit ok if the network printer name it correct you can see at printer and faxes windows how the check mark go from one printer to the ohter one.

RUNDLL32 PRINTUI.DLL,PrintUIEntry /q /y /n \\Server\hp5600
Edited by Danny35d
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

I just tested SetDefault($Printer) function in a winxp sp2, win2k sp4 and work fine setting a network and local printer as default.

As of troubleshooting I will open Printers and Faxes windows then I will open run window and paste the line below and hit ok if the network printer name it correct you can see at printer and faxes windows how the check mark go from one printer to the ohter one.

RUNDLL32 PRINTUI.DLL,PrintUIEntry /q /y /n \\Server\hp5600

When I input:

RUNDLL32 PRINTUI.DLL,PrintUIEntry /q /y /n \\server\hp5600

@ the c prompt it works great, I am somewhat puzzled why:

Func SetDefault($Printer)
   RunWait(@ComSpec & " /c RUNDLL32 PRINTUI.DLL,PrintUIEntry /q /y /n " & '"' & $Printer & '"', "", @SW_HIDE)
EndFunc

does not work because its basically the same thing?..?

Thanks a lot Danny35d! I think I can figure it out from here, unless you want to show me the finished product, I will post it once I puzzle through it.

Link to comment
Share on other sites

So this works, but it seems too simple, what problems may I run in to?

I plan on running this for specific users each time they log onto a pc, it will be in the DC login script.

$WshNetwork =  ObjCreate("WScript.Network")
$WshNetwork.AddWindowsPrinterConnection ("\\server\hp5600")
Run("RUNDLL32 PRINTUI.DLL,PrintUIEntry /q /y /n \\server\hp5600", "", @SW_MAXIMIZE)
Link to comment
Share on other sites

Final Code: looks more like AutoIt with the same results.

; Assign print share to current computer.
$WshNetwork =  ObjCreate("WScript.Network")
$WshNetwork.AddWindowsPrinterConnection ("\\server\hp5600")

; Set as default printer.
SetDefault("\\server\hp5600")
Func SetDefault($Printer)
   Run(@ComSpec & " /c RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n " & $Printer , "",@SW_HIDE)
EndFunc

It installs the share of the specified printer and then sets it as default printer.

Thanks for the help Danny35d.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...