Sign in to follow this  
Followers 0
schilbiz

Set Default Printer - *Solved*

10 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

... I use Rundll32 in my NetPrinter script below on my signature.

@danny,

The link on your Thread is dead

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

@Valuater thanks fixed.

@schilbiz try this:

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

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

@Valuater thanks fixed.

@schilbiz try this:

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

Same results, it creates the share in the list, but it does not assign it as default printer.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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

Share this post


Link to post
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.

Share this post


Link to post
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)

Share this post


Link to post
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.

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