|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
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 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 Show quote "ThunderMusic" <NOdanlatSPAM@hotmaildotcom> wrote in message news:e6MYKZaLGHA.2828@TK2MSFTNGP12.phx.gbl... > hi, > Is there an easy way to change the default printer from .net? > > thanks > > ThunderMusic > |
|||||||||||||||||||||||