Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can VB change the default printer?

Status
Not open for further replies.

Bishop72

Programmer
Jul 1, 1999
15
0
0
US
I need a way to switch the selected default from one installed/local printer to another installed/network printer transparently. I would like for it to act like a physical switch box. Is there an easy way to do this?<br>
<br>
Thanks!
 
Here is the example from vb help printer object.<br>
Dim X As Printer<br>
For Each X In Printers<br>
If X.Orientation = vbPRORPortrait Then<br>
' Set printer as system default.<br>
Set Printer = X<br>
' Stop looking for a printer.<br>
Exit For<br>
End If<br>
Next
 
Just slightley different....<br>
<br>
Dim X as Printer<br>
For Each X in Printers<br>
If X.DeviceName = "Name of Printer" Then ' ie "WINFAX" <br>
Set Printer = X<br>
Exit For<br>
End If<br>
Next<br>

 
Hail,

I tried the submitted code, but it does not work, only prints to my original default printer???
I'm running NT Server, could that be it?

Phailak
 
You have to modify the registry via an API to do this.
I have created a program that reads the current default printer, modifies it to my selection, starts an app, waits for the app to end and then brings the default printer to the original one.

I won't put the whole code in here but if you want it, just send an e-mail to sebasd@fenplast.com and i'll be happy to give it to you.

If you want to do it on your own, the API's are:
getprofilestring and writeprofilestring.
 
Phailak,

Which code submission did you use? [bb]thewhip[/bb]'s or [bb]markeymark[/bb]s?

thewhip's is, as they point out, a direct lift from the VB help file, and only sets the default printer to the first one that is set to print in portrait mode. This probably isn't all that useful to you, and could well give the impression that the code isn't doing anything

markeymark's is a modofied version that should allow you to set the default to a named printer (assuming you know that name). It should work fine (even under NT Server)

Note, however, that this technique merely changes the default printer for the VB application; it is [bb]not[/bb] a system-wide change. To affect that you have to resort to some minor registry work as mentioned by [bb]sebpas[/bb]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top