Solved

How do you set the default printer programatically?

Posted on 1998-08-11
6
169 Views
Last Modified: 2013-11-20
I want to set the default printer from my Win32 program.
The program should primarily run under Windows NT, but
it would be nice if it'd work under Windows 95/98 too.

   /Dan
0
Comment
Question by:danandersson
  • 2
  • 2
  • 2
6 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 1320537
How To Get and Set the Default Printer in Windows
http://support.microsoft.com/support/kb/articles/q135/3/87.asp

How to Set the Default Printer Programmatically in Windows 95
http://support.microsoft.com/support/kb/articles/q140/5/60.asp

0
 

Author Comment

by:danandersson
ID: 1320538
The primary platform I want to set the default printer is Windows NT. The given ansver from chensu did cover only 16-bit
Windows and Windows 95.
0
 
LVL 4

Expert Comment

by:agreen
ID: 1320539
In ALL versions of Windows, the appropriate way to get the default printer is to use GetProfileString, and the appropriate way to set the default printer is to use WriteProfileString.

The "HOWTO: Get and Set the Default Printer in Windows" applies to Win32 API which included with both NT and Win95.

So the chensu's answer is right.

I've already answered such question.
See http://www.experts-exchange.com\Q.10069298
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 4

Expert Comment

by:agreen
ID: 1320540
// To set the default printer for Windows NT use:
/* Note printer driver is usually WINSPOOL under Windows NT */

WriteProfileString("windows", "device", "My Printer, WINSPOOL,   "lpt1:");

SendMessageTimeout(HWND_BROADCAST, WM_WININICHANGE, 0L, 0L,
   SMTO_NORMAL, 1000, NULL);
0
 
LVL 23

Accepted Solution

by:
chensu earned 100 total points
ID: 1320541
The KB article does apply to Windows NT. Read it carefully please.

"This is the preferred method of changing the printer if the code is to be platform independent; this method will work on Windows 3.1, Windows 95 and Windows NT."

Thank you and also agreen.
0
 

Author Comment

by:danandersson
ID: 1320542
Thank you! Now I'm confident that this solves my problems :-)
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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
A short film showing how OnPage and Connectwise integration works.

943 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

5 Experts available now in Live!

Get 1:1 Help Now