Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to temporarily change printer then back again.

Posted on 2002-05-18
9
Medium Priority
?
315 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:roverm
ID: 7018748
(that is: "I've USED this ...." lol)
0
 
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 150 total points
ID: 7019527
And try this:

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

D'Mzzl!
RoverM
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

636 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