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

x
?
Solved

How do you set the default printer programatically?

Posted on 1998-08-11
6
Medium Priority
?
208 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
[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
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 400 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

610 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