Re: Set default printer for the machine
From: Willy Denoyette [MVP] (willy.denoyette_at_pandora.be)
Date: 10/21/04
- Next message: Marius Cabas: "Converting byte[] to string"
- Previous message: Jon Skeet [C# MVP]: "Re: DataTable.Select - System.Data.SyntaxErrorException"
- In reply to: Vivek: "Set default printer for the machine"
- Next in thread: Sahil Malik: "Re: Set default printer for the machine"
- Reply: Sahil Malik: "Re: Set default printer for the machine"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 21 Oct 2004 12:16:56 +0200
Using System.Management and WMI.
public static void Main() {
if (SetAsDefaultPrinter("Printerdev") != 0)
{
Console.WriteLine("Failed to set default printer");
}
}
static int SetAsDefaultPrinter(string printerDevice)
{
int ret = 0;
string path = "win32_printer.DeviceId='" + printerDevice + "'";
using (ManagementObject printer = new ManagementObject(path))
{
ManagementBaseObject outParams =
printer.InvokeMethod("SetDefaultPrinter",
null, null);
ret = (int)(uint)outParams.Properties["ReturnValue"].Value;
}
return ret;
}
Willy.
"Vivek" <vivek@nospam.com> wrote in message
news:u8b415xtEHA.3832@TK2MSFTNGP10.phx.gbl...
> Hi People,
>
> I want to change the default printer of the machine. I tried this.
>
> PrinterSettings pdDefault = new PrinterSettings();
>
> pdDefault.PrinterName = "PrinterName";
>
> It did not work. Please guide.
>
>
>
> Thanks
>
>
- Next message: Marius Cabas: "Converting byte[] to string"
- Previous message: Jon Skeet [C# MVP]: "Re: DataTable.Select - System.Data.SyntaxErrorException"
- In reply to: Vivek: "Set default printer for the machine"
- Next in thread: Sahil Malik: "Re: Set default printer for the machine"
- Reply: Sahil Malik: "Re: Set default printer for the machine"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|