473,566 Members | 2,958 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get Default printer WMI

Hi,

I'm trying to get the default printer using WMI.

I use the following code:

Private Function GetDefaultPrint er() As String
Dim objWMIService As Object
Dim colInstalledPri nters As Object
Dim objPrinter As Object
Dim strComputer As String
Dim strPrinter As String

strComputer = "MyComputerName "
objWMIService =
GetObject("winm gmts:{impersona tionLevel=imper sonate}!\\" & strComputer &
"\root\cimv 2")
colInstalledPri nters = objWMIService.E xecQuery("Selec t * from
Win32_Printer Where Default = True")
For Each objPrinter In colInstalledPri nters
strPrinter = objPrinter.Name ()
Next
GetDefaultPrint er = strPrinter
End Function

I've a printer installed as default printer, but the function returns to
printer. What is going wrong?

Many thanks in advance.

Willem
Nov 19 '05 #1
2 5578
Extra Info

Private Function GetDefaultPrint er2() As String
Dim oShell As Object
Dim sRegVal As String
Dim sDefault As String

oShell = CreateObject("W Script.Shell")
sRegVal = _
"HKCU\Software\ Microsoft\Windo ws NT\CurrentVersi on\Windows\Devi ce"
sDefault = ""
On Error Resume Next
sDefault = oShell.RegRead( sRegVal)
sDefault = Left(sDefault, InStr(sDefault, ",") - 1)
On Error GoTo 0
GetDefaultPrint er2 = sDefault
End Function

Is not working either. When I look in the registry I find a string, sDefault
stays empty.

I'm using Windows XP.

Willem
"Willem" wrote:
Hi,

I'm trying to get the default printer using WMI.

I use the following code:

Private Function GetDefaultPrint er() As String
Dim objWMIService As Object
Dim colInstalledPri nters As Object
Dim objPrinter As Object
Dim strComputer As String
Dim strPrinter As String

strComputer = "MyComputerName "
objWMIService =
GetObject("winm gmts:{impersona tionLevel=imper sonate}!\\" & strComputer &
"\root\cimv 2")
colInstalledPri nters = objWMIService.E xecQuery("Selec t * from
Win32_Printer Where Default = True")
For Each objPrinter In colInstalledPri nters
strPrinter = objPrinter.Name ()
Next
GetDefaultPrint er = strPrinter
End Function

I've a printer installed as default printer, but the function returns to
printer. What is going wrong?

Many thanks in advance.

Willem

Nov 19 '05 #2
asp.net runs as a service, and has no profile, thus no default printer.
specify the default printer name in the web config.

-- bruce (sqlwork.com)

"Willem" <Wi****@discuss ions.microsoft. com> wrote in message
news:DF******** *************** ***********@mic rosoft.com...
| Hi,
|
| I'm trying to get the default printer using WMI.
|
| I use the following code:
|
| Private Function GetDefaultPrint er() As String
| Dim objWMIService As Object
| Dim colInstalledPri nters As Object
| Dim objPrinter As Object
| Dim strComputer As String
| Dim strPrinter As String
|
| strComputer = "MyComputerName "
| objWMIService =
| GetObject("winm gmts:{impersona tionLevel=imper sonate}!\\" & strComputer &
| "\root\cimv 2")
| colInstalledPri nters = objWMIService.E xecQuery("Selec t * from
| Win32_Printer Where Default = True")
| For Each objPrinter In colInstalledPri nters
| strPrinter = objPrinter.Name ()
| Next
| GetDefaultPrint er = strPrinter
| End Function
|
| I've a printer installed as default printer, but the function returns to
| printer. What is going wrong?
|
| Many thanks in advance.
|
| Willem
|
|
Nov 19 '05 #3

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

Similar topics

1
13001
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
2568
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 the same reports to 3 different laserjets and to 3 different labelprinters. (They work with the db on 3 different units each with their own...
2
2101
by: MLH | last post by:
I would like to allow users to set, as an application default, a specific printer to send reports to. I don't know how to bring up a list of valid print devices in A97, nor do I know how to reference any one of them that might be selected. For instance, if I click Start, Control Panel, Printers and Faxes on a PC running XP and I see the...
3
25240
by: Raymond Martin | last post by:
How do I find out if the default printer is offline or online (or has a paper jam)?
0
1605
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 printers but network printers (they have been mapped using Local Port pointing to \\machine\printer - this was suggested in a topic - for a reason that...
1
5443
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 changed, Access 2003 still directs the report to the former default printer. Access 2003 picks up the new default printer setting only after I have...
1
2350
by: groulder | last post by:
hi all, i have a problem with a network database that's used by a lot of people. people are finding, they will start the database, and if the mouse is moved over the print icon, the tooltip appears to show which printer it will print to as normal. this printer however is a printer that the user doesn't even have installed.
2
17339
sashi
by: sashi | last post by:
Set default printer You will often find yourself in a position where you have designed a report format for one printer and when that report is sent to another printer the layout is messed up. The following code will allow you to specify the printer that reports are sent to by reseting the systems default printer. Windows API/Global...
3
4263
by: brianflannery | last post by:
Greetings all! My problem is this. I've installed a new printer on my computer. This is the "default printer" for access. Now, some of my reports, which were working fine with the old printer, are now showing up with an odd view (very enlarged) in preview. If I go to page setup, and choose specific printer to then look at the paper size...
0
7673
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7893
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7645
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6263
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5485
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2085
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1202
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.