473,405 Members | 2,349 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,405 software developers and data experts.

getting and setting the default printer

Hello,
How would you get and set the current default printer by using the
system.drawing.printing class or any other class.

Regards
Geri
Nov 21 '05 #1
3 3602
Hi,
Use the wmi for that. The win32_printer class has the
setdefaultprinter method.
' Add a Reference to System.Management

Dim moReturn As Management.ManagementObjectCollection

Dim moSearch As Management.ManagementObjectSearcher

Dim mo As Management.ManagementObject

moSearch = New Management.ManagementObjectSearcher("Select * from
Win32_Printer")

moReturn = moSearch.Get

For Each mo In moReturn

Dim strOut As String

strOut = String.Format("Name {0} ", mo("Name"))

Trace.WriteLine(strOut)

mo.InvokeMethod("SetDefaultPrinter", Nothing)

Next

Ken

------------------------
"Geraldine Hobley" <Ge*************@discussions.microsoft.com> wrote in
message news:76**********************************@microsof t.com...
Hello,
How would you get and set the current default printer by using the
system.drawing.printing class or any other class.

Regards
Geri
Nov 21 '05 #2
"Geraldine Hobley" <Ge*************@discussions.microsoft.com> schrieb:
How would you get and set the current default printer by using the
system.drawing.printing class or any other class.


Either use WMI or take a look at this article:

HOWTO: Retrieve and Set the Default Printer in Windows
<URL:http://support.microsoft.com/?scid=kb;EN-US;246772>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #3
Hi ken,
Thanx for the help, that allows me to set the default printer
perfectly, however how do I retrieve the default printer, as I need to
display this.

Regards
Geri.

"Ken Tucker [MVP]" wrote:
Hi,
Use the wmi for that. The win32_printer class has the
setdefaultprinter method.
' Add a Reference to System.Management

Dim moReturn As Management.ManagementObjectCollection

Dim moSearch As Management.ManagementObjectSearcher

Dim mo As Management.ManagementObject

moSearch = New Management.ManagementObjectSearcher("Select * from
Win32_Printer")

moReturn = moSearch.Get

For Each mo In moReturn

Dim strOut As String

strOut = String.Format("Name {0} ", mo("Name"))

Trace.WriteLine(strOut)

mo.InvokeMethod("SetDefaultPrinter", Nothing)

Next

Ken

------------------------
"Geraldine Hobley" <Ge*************@discussions.microsoft.com> wrote in
message news:76**********************************@microsof t.com...
Hello,
How would you get and set the current default printer by using the
system.drawing.printing class or any other class.

Regards
Geri

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Stephen Barrett | last post by:
I am doing word automation with Word 2003. Everything works great except for one thing. When I set the word object's ActivePrinter to a different printer, it changes the system default. I looked...
4
by: Umesh | last post by:
Hi all I am trying to change the printer(like paper source ,etc) setting in C#. But i am unable to do it. I am not sure how to do it. should i have to use WIN API like Openprinter , getprinter ,...
0
by: emde | last post by:
I am trying to set the default system printer and have got as far as listing the installed printers using PrinterSettings.InstalledPrinters. Anyone know how change the default printer? It needs to...
1
by: Geraldine Hobley | last post by:
Hello, I have the following code that sets the default printer using the WMI (windows management system). ' Add a Reference to System.Management Dim moReturn As...
3
by: Panos | last post by:
Hi, is there a way that i could get the default printer of the system? I'm using VB.net 2001. There is a function in SDK called "GetDefaultPrinter", but i don't understand how to use it.
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: sathyp | last post by:
Public Function SetPrinterDefaultsW(ByVal sPrinterName As String, _ ByVal nPaperSize As Long, ByVal nOrientation As Long) As Boolean Dim Prn As Printer Dim hPrinter As Long Dim pd As...
5
by: Glenn | last post by:
Hi We have a ASP.net app which calls into a web service which allow users to print stuff. At the moment they have to specify the printer. Apparently this is too much for our users, so I was...
13
by: Mark Rae | last post by:
Hi, I have used the code below to return the default printer in 32-bit WinXP Pro, but now that I am running 64-bit Vista Business I'm getting an error: using System.Drawing.Printing; using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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...
0
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...

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.