AutoHotkey Community

It is currently May 27th, 2012, 11:04 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: April 14th, 2007, 2:21 pm 
Offline

Joined: April 13th, 2007, 6:56 pm
Posts: 6
Location: Unterschleißheim, BY, DE
:idea:

Thanks to Sean and his great idea, I could think of a solution to switch my default printer within a given list (of, in this case, 2 printers).

Of course, you could think of something like cycling through a whole array of printers.

Code:
LWin & PrintScreen::

Printer1 = Minotaurus   ; change according to your Printer1
Printer2 = Adobe PDF   ; change according to your Printer2

If (GetDefaultPrinter() = Printer1)
{
   SetDefaultPrinter(Printer2)
}
Else
{
   SetDefaultPrinter(Printer1)
}

GetDefaultPrinter()
{
   nSize := VarSetCapacity(gPrinter, 256)
   DllCall(A_WinDir . "\system\winspool.drv\GetDefaultPrinterA", "str", gPrinter, "UintP", nSize)
   Return gPrinter
}
      
SetDefaultPrinter(sPrinter)
{
   DllCall(A_WinDir . "\system\winspool.drv\SetDefaultPrinterA", "str", sPrinter)
   TrayTip, AHK » Drucker und Faxgeräte, %sPrinter% wurde als Standard definiert., 10, 17
   ; the English translation would be:
   ; AHK » Printers and Faxes, %sPrinter% set as default printer.
   Sleep, 3000
   TrayTip
}
return


Note that the tray tip causes a delay of 3 seconds before another switch can be triggered.

Update 2008-02-09: on Vista-based machines, please replace the two "\system\" sections by "\System32\". Enjoy!

I hope this comes in handy to somebody as it did for me. :D
Christian Sentis

_________________
On-on!


Last edited by controlfreak on February 9th, 2008, 10:31 am, edited 3 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 16th, 2007, 7:57 am 
Offline

Joined: October 30th, 2006, 10:17 pm
Posts: 43
Why don't you make a pop up menu??

_________________
Tex© Click here to mail me


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Doesnt work..
PostPosted: August 20th, 2007, 3:48 pm 
Thanx for the script, the idea sounds very usefull. But it doesnt work on my windows version (XP). It shows the message and all seems well, but my printer doesnt get changed. I tried a few different name styles for my printers, but all dont work.

Could it be that my version of winspool.drv doesnt support printer change?

Any idea?

Thanx!
Randy


Report this post
Top
  
Reply with quote  
PostPosted: August 20th, 2007, 3:56 pm 
:oops:

I found the answer in the post you mentioned at the top, I overlooked that one. Sorry..

In my case it missed a network adress: "/a100/".

Again, great idea... for me it's very usefull! :D

Greets,
Randy


Report this post
Top
  
Reply with quote  
PostPosted: August 20th, 2007, 7:48 pm 
randy@ahk wrote:
Again, great idea... for me it's very usefull! :D


Randy,

Thank you for your appreciated feedback! Always nice to hear :)

Christian


Report this post
Top
  
Reply with quote  
 Post subject: Cool Script !
PostPosted: January 5th, 2009, 3:19 am 
Offline

Joined: November 10th, 2006, 5:10 am
Posts: 110
Cool Script !

Does this work for Microsoft Word ? (Office can be pickier than other apps about printer changing).

I found this app: Defptr.exe which does a great job, but I often like AHK solutions :D

http://www.watchingthenet.com/change-de ... ndows.html


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Works great!
PostPosted: September 18th, 2009, 10:53 pm 
I just had to add a network address in front of my printer name. If you don't know what your printer's full name is, add the following to your script:

vPrinter := GetDefaultPrinter()
MsgBox, Default printer name is %vPrinter%.

Thanks for the great script!

- David


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 20th, 2010, 7:35 pm 
Offline

Joined: June 2nd, 2008, 7:03 pm
Posts: 44
Thanks for the sweet script!

The tooltip wasn't working properly for me, so I added this line to pop up a MsgBox for a couple seconds:

Code:
MsgBox ,0,Printers and Faxes,%sPrinter% set as default printer, 2


Thanks again!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 4th, 2010, 5:07 pm 
Offline

Joined: February 25th, 2010, 4:55 pm
Posts: 8
Location: USA
So I have tried using this code, but the message shows up saying it changed my printer but it really did not.

I'm new at this, so maybe I'm not changing something in accordance to my printers. Can someone tell me if I need to change this part? If I need to find my network adrs, tell me how, please.

Code:
DllCall(A_WinDir . "\system32\winspool.drv\SetDefaultPrinterA", "str", sPrinter)
   TrayTip, AHK » Printers and Faxes, %sPrinter% set as default printer., 10, 17


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 4th, 2010, 9:43 pm 
Offline

Joined: January 29th, 2009, 9:50 pm
Posts: 483
Location: Belgium
i use:
Code:
DllCall("winspool.drv\GetDefaultPrinterA", "str", gPrinter, "UintP", nSize)

without system or system32 and it works fine

_________________
Stopwatch emdkplayer
the code i post falls under the: WTFYW-WTFPL license


Report this post
Top
 Profile  
Reply with quote  
PostPosted: March 10th, 2010, 6:27 pm 
Okay, first I would like to thank everyone on the code for switching default printers. I am totally green on this, but here is my situation.

I test printer cartridges on about 20 different printers hooked up to one computer. I would like to be able to use a hotkey to switch from printer to printer and to print our test page.

Code:
Numpad2::
LWin & PrintScreen::

Printer1 = hp psc 1310 series


{
   SetDefaultPrinter(Printer1)
}

     
SetDefaultPrinter(sPrinter)
{
   DllCall(A_WinDir . "\System32\winspool.drv\SetDefaultPrinterA", "str", sPrinter)
   TrayTip, AHK » Printers and Faxes, %sPrinter% set as default printer., 10, 17
   ; the English translation would be:
   ; AHK » Printers and Faxes, %sPrinter% set as default printer.
   Sleep, 3000
   TrayTip
}
Runwait, print "C:\Users\Admin\Desktop\OCP Color Test Chart.pdf"
return


I can switch the default printers and it will print the test page. However, I often print multiple test pages on multiple printers, and when I make another switch, it prints to the printer that is currently printing. Any help would be greatly appreciated[/code]


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 11th, 2010, 5:00 pm 
Offline

Joined: February 25th, 2010, 4:55 pm
Posts: 8
Location: USA
Oink, I can't help you, but Ihave a question for you or anyone else who can help. I'm using basically the same script to change the default printer.
Code:
Printer1 = HP LaserJet 9000 PCL 5e


{
   SetDefaultPrinter(Printer1)
}

     
SetDefaultPrinter(sPrinter)
{
   DllCall("winspool.drv\GetDefaultPrinterA", "str", gPrinter, "UintP", nSize)
   TrayTip, AHK » Printers and Faxes, %sPrinter% set as default printer., 10, 17
   Sleep, 3000
   TrayTip
}
Return


The problem is is that a pop up box shows it has changed the printer, but I go back to look manually at printers and faxes and it has never changed it. Does anyone have any idea what I'm doing wrong?
Thanks.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2010, 5:42 pm 
Offline

Joined: January 29th, 2009, 9:50 pm
Posts: 483
Location: Belgium
use something like this:
Code:
Numpad0::MsgBox , ,Default printer name is, % GetDefaultPrinter()   ; check default printer
Numpad1::SetDefaultPrinter("hp psc 1310 series")               ; set a default printer
Numpad2::SetDefaultPrinter("hp psc 1310 series")               ; set a other defaulty printer
SetDefaultPrinter(sPrinter) {
   DllCall(A_WinDir . "\system\winspool.drv\SetDefaultPrinterA", "str", sPrinter)
   TrayTip, AHK » Printers and Faxes, %sPrinter% set as default printer., 10, 17
   Sleep, 3000
   TrayTip
   }
GetDefaultPrinter() {
   nSize := VarSetCapacity(gPrinter, 256)
   DllCall("winspool.drv\GetDefaultPrinterA", "str", gPrinter, "UintP", nSize)
   Return gPrinter
   }
No need to use variables, and u can check the default printer by pressing numpad0

_________________
Stopwatch emdkplayer
the code i post falls under the: WTFYW-WTFPL license


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 2nd, 2010, 3:16 pm 
Offline

Joined: April 30th, 2010, 12:40 am
Posts: 68
This script is a-mazing

Fixed a huge issue we had at work. Our IT department stupidly set us up so that the computer won't return to the default printer after printing to a different location (most often, Adobe PDF). This totally fixed that problem.

Thanks!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 8th, 2011, 11:04 am 
Offline

Joined: June 10th, 2011, 10:09 am
Posts: 2
Location: The Netherlands
Hey guys,

I just added this little script to my long autohotkey script, but it doesn't work.

Okay, the tooltip works :wink:

I changed the 'Dllcal' part to the proper directory (\system32\winspool.drv). I also checked of this file exists, and yes it does.

Any ideas how I can get this to work? (I'm running Windows 7)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: iDrug and 60 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group