473,800 Members | 2,893 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1587
Hi,

There are three options I am aware of..
1) Using WMI and invoking the SetDefaultPrint er method on the Win32_Printer
object
2) Interop and call the Win32 API function SetDefaultPrint er
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
SetDefaultPrint er method of each of the printers. For this you will need to
add a reference to the System.Manageme nt assembly.

System.Manageme nt.ManagementOb jectSearcher search;
System.Manageme nt.ManagementOb jectCollection results;

search = new System.Manageme nt.ManagementOb jectSearcher("s elect *
from win32_printer") ;
results = search.Get();

foreach (System.Managem ent.ManagementO bject printer in results)
{
System.Diagnost ics.Debug.Write Line(printer["Name"]);
printer.InvokeM ethod("SetDefau ltPrinter", null);
}

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

Hope this helps

Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor
"ThunderMus ic" <NOdanlatSPAM@h otmaildotcom> wrote in message
news:e6******** ******@TK2MSFTN GP12.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
13027
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
7126
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 the printer destination for special reports such as stickers and mailing labels. The Mailing Label report is, of course, designed here for a specific printer (Mailing Label). At another site, the name could be completely different. Other than...
2
7750
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
2881
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 tell me how to do that? I have some unmanaged code that no longer works for some unknown reason.
1
18361
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 has a local printer, the report is prints locally. What I'm I doing wrong! The complete subroutine follows: Private Sub PrintReport(strReportName As String) On Error GoTo PrintReport_Err
7
20732
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 printer's physical margins using VB coding? Cheers -- Osmotion Blue
8
2886
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 printer from the default printer for that report to a PDF995 printer (so that i can print it to a file for subsequent emailing) then back to the default Epsom 830 printer? Thanks for any help Phil
0
1420
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, preview, or print mode. If I change my default printer to some other printer it will work. Interesting point also is that I can print to the original printer as long as it is not set as the default?
3
4148
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? txtfile.WriteLine(xmlhttp.responseText) txtfile.Close 'enable this to print 'oWS.Run "NotePad.exe /p " + path Unrelated, the page printed is set for letter size paper width so some lines print a few characters, then...
0
10501
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10273
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10250
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10032
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7574
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5603
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2944
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.