Solved

How to temporarily change printer then back again.

Posted on 2002-05-18
9
302 Views
Last Modified: 2010-05-02
I want my app to temporarily change printer output to a specific printer (PDF Print Device) and then back to the original default printer on the system.
I will not know the default printer name in advance.
In a couple lines of code, how do I do it?
0
Comment
Question by:rbend
  • 6
  • 2
9 Comments
 
LVL 12

Expert Comment

by:roverm
ID: 7018726
Change it in the registry:

Key : HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows
String : Device

The value here is the current default printer.
Change it here in code.

D'Mzzl!
RoverM

(btw: This is the key for W2000Pro. If it not exists on your machine just do a search in the registry for your current default printer. To verify: change the default and see if the key has changed.)
0
 

Author Comment

by:rbend
ID: 7018739
This may work, but this will be happening very frequently and I don't want to write code to search the registry and mess with that each time.
I will opt for a less intrusive answer to the problem.
Thanks.
0
 
LVL 12

Expert Comment

by:roverm
ID: 7018745
You don't have to write the code to search the registry.
If you have found it once, manually, you can use this key to alter it as many times as you would like!

Just read it back b4 changing it (else you can't reset it to the original value ;-) ).

I KNOW this will work, I've this way in several applications.

D'Mzzl!
RoverM
0
 
LVL 12

Expert Comment

by:roverm
ID: 7018748
(that is: "I've USED this ...." lol)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 18

Expert Comment

by:bobbit31
ID: 7018757
you could do it this way:

Dim defaultPrinter as Printer

set defaultPrinter = Printer

For Each p In Printers
   If p.DeviceName = "Your PDF Printer" Then '' you could also use the port for comparison
      Set Printer = p
   End If
next

'' your default printer is now Your pdf printer
'' do what you need here

'' set Printer back to default
set Printer = defaultPrinter

0
 
LVL 12

Expert Comment

by:roverm
ID: 7018764
bobbit31:
Yep, that will work, IF the PDF device will use the vb printer object.
When I build my apps, the device wasn't used (by the DataReport.... duh!!)

D'Mzzl!
RoverM
0
 

Author Comment

by:rbend
ID: 7019044
roverm:
This app will be distributed to PC's without my knowledge and without me being able to find out the registry contents. Therefore, the app would have to do the hunting each time.
0
 
LVL 12

Expert Comment

by:roverm
ID: 7019461
Only if the PC have different OS than yours. But if you have no knowledge of them at all then I suppose it will be more difficult.

The key I provided is correct for WinNT, 2000 and XP systems (and maybe ME). The only difference with 95/98 is (AFAIK) that the subkey "Windows NT" should be "Windows".
Maybe worth trying ?

D'Mzzl!
RoverM
0
 
LVL 12

Accepted Solution

by:
roverm earned 50 total points
ID: 7019527
And try this:

http://www.freevbcode.com/ShowCode.Asp?ID=641

D'Mzzl!
RoverM
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now