HOWTO: Get and Set the Default Printer in WindowsLast reviewed: March 4, 1998Article ID: Q135387 |
The information in this article applies to:
SUMMARYIn 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. This works whether the default printer information is stored in the WIN.INI file or in the registry.
MORE INFORMATION
Notes to Keep in Mind
Sample Code
// This code uses a sample profile string of "My Printer,HPPCL5MS,lpt1:" // To get the default printer for Windows 3.1, Windows 3.11, // Windows 95, and Windows NT use: GetProfileString("windows", "device", ",,,", buffer, sizeof(buffer)); ----- // To set the default printer for Windows 3.1 and Windows 3.11 use: WriteProfileString("windows", "device", "My Printer,HPPCL5MS,lpt1:"); SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, 0L); ----- // To set the default printer for Windows 95 use: WriteProfileString("windows", "device", "My Printer,HPPCL5MS,lpt1:"); SendMessageTimeout(HWND_BROADCAST, WM_WININICHANGE, 0L, (LPARAM)(LPCTSTR)"windows", SMTO_NORMAL, 1000, NULL); ----- // 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);There are two circumstances where the code won't work:
For additional information, please see the following article(s) in the Microsoft Knowledge Base:
ARTICLE-ID: Q140560 TITLE : How to Set the Default Printer Programmatically in Windows 95 |
Additional query words: 3.11
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |