 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
controlfreak
Joined: 13 Apr 2007 Posts: 7 Location: Unterschleißheim, BY, DE
|
Posted: Fri Apr 13, 2007 7:15 pm Post subject: HELP! There must be an easy way: get default printer's name |
|
|
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 ):
| 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%
|
Thank you for your kind help!  _________________ On-on! |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3842 Location: Bremen, Germany
|
Posted: Fri Apr 13, 2007 8:55 pm Post subject: |
|
|
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 |
|
 |
Zippo() Guest
|
Posted: Fri Apr 13, 2007 11:52 pm Post subject: |
|
|
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
|
Posted: Sat Apr 14, 2007 7:05 am Post subject: |
|
|
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 |
|
 |
controlfreak
Joined: 13 Apr 2007 Posts: 7 Location: Unterschleißheim, BY, DE
|
Posted: Sat Apr 14, 2007 2:00 pm Post subject: Finally! Thank you so much! |
|
|
@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 |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|