Solved

How to temporarily change printer then back again.

Posted on 2002-05-18
9
301 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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 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 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…

707 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

15 Experts available now in Live!

Get 1:1 Help Now