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

Discussion in 'ASP .Net' started by ThunderMusic, Feb 9, 2006.

  1. ThunderMusic

    ThunderMusic Guest

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

    thanks

    ThunderMusic
     
    ThunderMusic, Feb 9, 2006
    #1
    1. Advertising

  2. ThunderMusic

    Chris Taylor Guest

    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:...
    > hi,
    > Is there an easy way to change the default printer from .net?
    >
    > thanks
    >
    > ThunderMusic
    >
     
    Chris Taylor, Feb 12, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Samuel Lee
    Replies:
    0
    Views:
    528
    Samuel Lee
    Nov 11, 2003
  2. cyberco
    Replies:
    0
    Views:
    3,643
    cyberco
    Nov 11, 2004
  3. Ace_12
    Replies:
    0
    Views:
    917
    Ace_12
    Sep 22, 2006
  4. Ron Garret
    Replies:
    4
    Views:
    332
    Peter Otten
    Aug 21, 2007
  5. Domenico Discepola

    How to change default printer in Windows using Perl

    Domenico Discepola, Jul 16, 2004, in forum: Perl Misc
    Replies:
    1
    Views:
    302
    Domenico Discepola
    Jul 16, 2004
Loading...

Share This Page