AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

HELP! There must be an easy way: get default printer's name

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
controlfreak



Joined: 13 Apr 2007
Posts: 7
Location: Unterschleißheim, BY, DE

PostPosted: Fri Apr 13, 2007 7:15 pm    Post subject: HELP! There must be an easy way: get default printer's name Reply with quote

Could anyone please help me out? I have thoroughly searched the forum and not yet found what I am looking for. Yet there must be an easy solution!?

Out of 4 printers, I would like to use 2 for switching between them upon a hotkey trigger. The names of the two printers to be used are "Minotaurus" and "Adobe PDF". This is what I got so far:

Code:
sPrinter = "Adobe PDF"

RunWait, rundll32.exe printui.dll`,PrintUIEntry /y /n %sPrinter%

TrayTip, AHK » Drucker und Faxgeräte, %sPrinter% wurde als Standard definiert., 10, 17
Sleep, 1000
TrayTip


My aim is to set the string "sPrinter" depending on the (current) default printer. Is there any way to check the system's default printer's name and have something like (VB-style, beware Laughing ):

Code:
dPrinter = DefaultPrinter
If dPrinter = "Adobe PDF" Then
   sPrinter = "Minotaurus"
Else: sPrinter = "Adobe PDF"
End If

RunWait, rundll32.exe printui.dll`,PrintUIEntry /y /n %sPrinter%


Question

Thank you for your kind help! Wink
_________________
On-on!
Back to top
View user's profile Send private message
toralf



Joined: 31 Jan 2005
Posts: 3842
Location: Bremen, Germany

PostPosted: Fri Apr 13, 2007 8:55 pm    Post subject: Reply with quote

If you can't get that info from they properties
Code:
Get printer settings saving results in a file:
RUNDLL32 PRINTUI.DLL,PrintUIEntry /f "results.txt" /Xg /n "printer"
 
Store all printer settings into a file:
RUNDLL32 PRINTUI.DLL,PrintUIEntry /Ss /n "printer" /a "file.dat"
You might memorize the last printer you used and toggle. Then it might only the first time not toggle correctly.
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Zippo()
Guest





PostPosted: Fri Apr 13, 2007 11:52 pm    Post subject: Reply with quote

Can't you use the registry?

Code:
If A_OSVersion in WIN_NT4,WIN_95,WIN_98,WIN_ME
  {
    Root := "HKLM"
    Sub  := "Config\0001\System\CurrentControlSet\Control\Print\Printers"
    VN   := "Default"
  }
Else
  {
    Root := "HKCU"
    Sub  := "Software\Microsoft\Windows NT\CurrentVersion\Windows"
    VN   := "Device"
  }

RegRead, OutputVar, %Root%, %Sub%, %VN%
StringSplit, OutputVar, OutputVar, `,

MsgBox % OutputVar1
Back to top
Sean



Joined: 12 Feb 2007
Posts: 1323

PostPosted: Sat Apr 14, 2007 7:05 am    Post subject: Reply with quote

Another could-be solution.

Code:
MsgBox % GetDefaultPrinter()

GetDefaultPrinter()
{
   nSize := VarSetCapacity(sPrinter, 256)
   DllCall("winspool.drv\GetDefaultPrinterA", "str", sPrinter, "UintP", nSize)
   Return sPrinter
}

SetDefaultPrinter(sPrinter)
{
   DllCall("winspool.drv\SetDefaultPrinterA", "str", sPrinter)
}
Back to top
View user's profile Send private message
controlfreak



Joined: 13 Apr 2007
Posts: 7
Location: Unterschleißheim, BY, DE

PostPosted: Sat Apr 14, 2007 2:00 pm    Post subject: Finally! Thank you so much! Reply with quote

@toralf: I tried to find a solution using your hints but was unwilling to deal with file i|o when there must have been a system variable or else. Nevertheless: thank you for your fast reply!

@Zippo(): unfortunately none of the given registry keys helped me out. With WinXP, it had to be the second path - but: no info/key/value indicating which of my 4 devices is defined as standard. Thank you for your kind reply.

@Sean: thanks, buddy, this works like a charm. Before, I was dominated by the idea of using PrintUI.dll. But this is what finally did it for me (I will post it within the forum "Scripts & Functions"):

[edit 2007-04-21]http://www.autohotkey.com/forum/viewtopic.php?t=18348[/edit]

Code:
LWin & PrintScreen::

Printer1 = Minotaurus
Printer2 = Adobe PDF

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
   Sleep, 3000
   TrayTip
}
return

_________________
On-on!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group