473,385 Members | 1,673 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.

Set default printer for the machine

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
Nov 16 '05 #1
3 30240
Your answer is right here
http://support.microsoft.com/default...b;EN-US;246772

In short - there is no managed .NET way of doing it.

- Sahil Malik
http://www.dotnetjunkies.com/weblog/sahilmalik
"Vivek" <vi***@nospam.com> wrote in message
news:u8**************@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

Nov 16 '05 #2
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" <vi***@nospam.com> wrote in message
news:u8**************@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

Nov 16 '05 #3
Fantastic !!

--
- Sahil Malik
http://www.dotnetjunkies.com/weblog/sahilmalik
Please reply to the newsgroups instead of email so everyone can benefit from
your reply.
"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:OV****************@TK2MSFTNGP14.phx.gbl...
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" <vi***@nospam.com> wrote in message
news:u8**************@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


Nov 16 '05 #4

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
0
by: Brian Boccia | last post by:
I'm trying to print a report from an ASP.Net button click event. In my application I use a ReportDocument object to load a .rpt file and display the file in an IE window. In that window I have an...
0
by: Esmee | last post by:
Hi there, I have created an Access 2002 db which contains several reports. Some reports need to be printed on a Laserjet and others on a Labelprinter. One of my clients wants to be able to print...
0
by: Karthick_Microsoft | last post by:
Actually, in my ASP.Net application, i have a requirement of automatically changing the default printer. I did a OCX using VB and put it on the web page. The client machines do not have local...
1
by: i8mypnuts | last post by:
Could someone please help? I am using the 'defaultprt.zip' tool provided by Ken Getz to change the default printer via VBA code (code below). My problem is that once the default printer has been...
4
by: c_shah | last post by:
How to change and set default printer using Visual Basic 2005 The following works within my VB 2005 application but does any one have better alternative. /**** Dim wshnetwork As Object =...
2
by: TARUN | last post by:
Hello all, Please help and suggest the code to get the printer status over the network. for Example, i have an string "\\\\os1\\PtName" where os1 is the system name and PtName is the printer...
1
by: ekynox | last post by:
Hi guys, have been playing with WMI to add a network printer connection to a Windows XP pc. My environment consists of a server running Windows Server 2003 and Visual Studio 2005 and a test pc...
4
by: David C. Barber | last post by:
my.computer.printers.defaultprinter doesn't exist in 2005, despite the plethora of examples still out on the web detailing its use. So how can I determine a person's default printer using ASP 2?...
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.