Solved

How to temporarily change printer then back again.

Posted on 2002-05-18
9
308 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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 50 total points
ID: 7019527
And try this:

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

D'Mzzl!
RoverM
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

724 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