473,385 Members | 1,642 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Is there an easy way to change the default printer from .net?

hi,
Is there an easy way to change the default printer from .net?

thanks

ThunderMusic
Feb 9 '06 #1
1 1547
Hi,

There are three options I am aware of..
1) Using WMI and invoking the SetDefaultPrinter method on the Win32_Printer
object
2) Interop and call the Win32 API function SetDefaultPrinter
3) Manipulate the registry directly and sent a broadcast message to all
applications

In my opinion option one is the cleanest option from .NET followed by option
2 and option 3 is a last resort in the case where you need to support OS
prior to Windows 2000.

The following example will enumerate the printers using WMI and invoke the
SetDefaultPrinter method of each of the printers. For this you will need to
add a reference to the System.Management assembly.

System.Management.ManagementObjectSearcher search;
System.Management.ManagementObjectCollection results;

search = new System.Management.ManagementObjectSearcher("select *
from win32_printer");
results = search.Get();

foreach (System.Management.ManagementObject printer in results)
{
System.Diagnostics.Debug.WriteLine(printer["Name"]);
printer.InvokeMethod("SetDefaultPrinter", null);
}

If you need more info on the other options, just post here.

Hope this helps

Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor
"ThunderMusic" <NOdanlatSPAM@hotmaildotcom> wrote in message
news:e6**************@TK2MSFTNGP12.phx.gbl...
hi,
Is there an easy way to change the default printer from .net?

thanks

ThunderMusic

Feb 11 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Pablo | last post by:
Friends, how can i get the name of the default printer??. I'm working with winforms. VB,C#, nevermind. Thanks a lot Pablo
5
by: Hank | last post by:
My Access 2000 code has been running for several years in our main plant. Now we need to install it, as a stand-along application, at remote sites, some of which are out of state. My problem is...
2
by: Pablo | last post by:
Friends, I need to change the default printer from code, with no user iterativity. Any sample code? suggestion? C#,VB, nevermind!. Thanks Pablo
2
by: Just Me | last post by:
I want to programmatically change the paper orientation of the systems default printer in such a way that the new orientation shows for the printer under: Start/Printer and Faxes Can anyone...
1
by: PCB | last post by:
Hi all! I have a subroutine that prints reports on a specific printer. The code works fine as long as all the printers available to the computer are on the network. However, if the computer also...
7
by: Mark | last post by:
Hi, I am creating application in VB 2005. and when I print report it adds extra 0.45 cm margin on left and top, and the reason for this is physical margins of printer. Is it possible to change...
8
by: Phil Stanton | last post by:
Using Access 2000 (Yes I know there is no Printer specified) and an MDE File (Yes I know I can't open a report in design view). Is there any way using VBA of temporarily changing the report's...
0
by: AP | last post by:
I have had this before in the past and just ignored it, but now I need a solution. Basically, using ACC2003 if I have one particular printer as the default, the reports will not open in design,...
3
drhowarddrfine
by: drhowarddrfine | last post by:
I have a simple vbscript that extracts a web page, saves it to a file, then uses notepad to print that file to the default printer. What can I do to make it print to a specified non-default printer?...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.