|
-
September 14th, 2011, 10:21 AM
#1
[RESOLVED] Retrieve Printer Name
OK, This should be very simple but.....
Does anybody know how to retrive a list of the names of the currently installed printers. This seems simple enough using the printers collection and the DeviceName property but on network printers this property is returning the network path and not the description/name of the printer. I have tried Google on this but it is returning far too many results which are not related. I am using Windows 7 if this makes any odds.
Thanks
-
September 14th, 2011, 11:14 AM
#2
Re: Retrieve Printer Name
So, you want to know all the names and details of all the printers. Connected via LAN? I suppose next, you'll want to be able to find all the names of all the printers ON THE INTERNET...
See the issue? We post code, bad guys use it to print on my printer tomorrow.
Printers are controlled by PERMISSIONS. If the printer is mapped (NET USE) it will be LPT1, LPT2, or LPT3.
-
September 14th, 2011, 11:29 AM
#3
Re: Retrieve Printer Name
dglienna,
I am sorry if I did not make myself clear. I have a number of printers installed on my PC. Some of these printers are local and some are network printers. All of these printers are installed and have the relevant network addresses and passwords.
I would like to retrieve a list of the names of the printers as they are shown in my control panel.
Using the DeviceName property I can retrieve the names of the local printers exactly as they are shown in the control panel, however, all of the network printers return a network path and not the printer name.
-
September 14th, 2011, 11:59 AM
#4
Re: Retrieve Printer Name
Here is a little piece of code I wrote years ago that populates a combo with the list of installed printers.
Code:
Dim x As Integer
Combo1.Clear
Combo1.Text = Printer.DeviceName ' This is the default printer
For x = 0 To Printers.Count - 1
Combo1.AddItem Printers(x).DeviceName ' this will show all printers including the default one above.
Next
Always use [code][/code] tags when posting code.
-
September 14th, 2011, 01:07 PM
#5
Re: Retrieve Printer Name
Thanks for this dglienna, but this brings us back to the original problem which is that the DeviceName function is returning the network path and not the name as displayed in the control panel.
For example my default printer is displayed in the control panel as 'HP LaserJet 6P on ronan' but the Printer.DeviceName method returns '\\ronan\HP LaserJet 6P'. I am not sure if this is something specific to Windows 7 or not but still very odd.
-
September 14th, 2011, 02:01 PM
#6
Re: Retrieve Printer Name
I'm afraid the way it comes up is the way it is. That is the actuall device name. Windows is simply changing the way it is displayed in the area you are looking at. You could do this yourself if you want to write the code.
Parse the string in devicename, if it begins with \\ drop those off split on \ then assign to a new string from the resulting array
Code:
MyPrinterName=MyArray(1) & " on " & MyArray(0)
Then display MyPrinterName rather than the actual device name.
So
\\p42800\HP LaserJet 1020
becomes
HP LaserJet 1020 on p42800
Last edited by DataMiser; September 14th, 2011 at 02:10 PM.
Always use [code][/code] tags when posting code.
-
September 14th, 2011, 02:28 PM
#7
Re: Retrieve Printer Name
OK, Thanks for your help.
I will have to go back to the drawing board and check the API. Your idea with the string manipulation wont help in this scenario as the printer could have been called anything. There must be some way of accessing this informaion as the control panel and the standard printer common dialog both have the correct printer name.
ARGHHH!!
-
September 14th, 2011, 02:44 PM
#8
Re: Retrieve Printer Name
Always use [code][/code] tags when posting code.
-
September 15th, 2011, 10:35 AM
#9
Re: Retrieve Printer Name
I had this sophisticated, yet simple little VB Script, which makes use of the WMI mechanism to obtain a list of all printers and shows some of their attributes.
Code:
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Printer",,48)
For Each objItem in colItems
if MsgBox( _
"Attributes: " & objItem.Attributes & chr(13) & chr(10) _
& "Availability: " & objItem.Availability & chr(13) & chr(10) _
& "Caption: " & objItem.Caption & chr(13) & chr(10) _
& "Comment: " & objItem.Comment & chr(13) & chr(10) _
& "DeviceID: " & objItem.DeviceID & chr(13) & chr(10) _
& "DriverName: " & objItem.DriverName & chr(13) & chr(10) _
& "ExtendedPrinterStatus: " & objItem.ExtendedPrinterStatus & chr(13) & chr(10) _
& "Location: " & objItem.Location & chr(13) & chr(10) _
& "Name: " & objItem.Name & chr(13) & chr(10) _
& "Network: " & objItem.Network & chr(13) & chr(10) _
& "PortName: " & objItem.PortName & chr(13) & chr(10) _
& "ServerName: " & objItem.ServerName & chr(13) & chr(10) _
& "Shared: " & objItem.Shared & chr(13) & chr(10) _
& "ShareName: " & objItem.ShareName & chr(13) & chr(10) _
& "Status: " & objItem.Status & chr(13) & chr(10) _
& "StatusInfo: " & objItem.StatusInfo & chr(13) & chr(10) _
& "SystemCreationClassName: " & objItem.SystemCreationClassName & chr(13) & chr(10) _
& "SystemName: " & objItem.SystemName,1 _
) = 2 then Exit For
Next
The required name should be within the display.
There are much more properties available, but I have only displayed the most important for identifying.
The little script runs directly from within a text file with the .vbs ending, but the wMI query mechanism can surely be adapted easily to run within a VB program.
-
September 15th, 2011, 05:15 PM
#10
Re: Retrieve Printer Name
I've used a XEROX COLOR LASER PRINTER that printed 10 pages per second, and could print 5 different inks on each side at the same time (including magnetic ink). My point, is that PERMISSIONS are the issue.
-
September 15th, 2011, 05:30 PM
#11
Re: Retrieve Printer Name
In my case permissions are not the issue running under XP in admin mode, still get the same results. The printer object just does not return the value keyed in by the user. Instead it gets the physical path\name of the printer. If permissions were the issue then this is what would be blocked as this is what you would need to access the printer. The name keyed in by the user is just for show no permission issues there.
Always use [code][/code] tags when posting code.
-
September 16th, 2011, 10:40 AM
#12
Re: Retrieve Printer Name
Please try again with my little script and take regard to the following.
The caption and the DeviceID seem to be the same always. They change both if you rename the printer.
If you share the printer you may give it a share name which appears in the network.
I inspected all our printers and the Caption property reflected always the name as shown to me in the control panel, not the network path.
-
September 16th, 2011, 12:09 PM
#13
Re: Retrieve Printer Name
Just to be clear I did not try the script as I have no need for this at present. I was referring only to the printer object and permissions.
The script should be of use to the OP
Always use [code][/code] tags when posting code.
-
September 20th, 2011, 08:18 AM
#14
Re: Retrieve Printer Name
That's what I hoped.
-
September 20th, 2011, 11:46 AM
#15
Re: Retrieve Printer Name
Thanks guys for your efforts, I have used a bit of WOF's idea with the WIN32_Printer collection (Network Property) to let me know if it is a network printer and then build the printer desciption accordingly (as per DataMiser's suggestion). I tried all of the string properties of the Win32_Printer but none of them gave me the name as displayed in the control panel/printer dialog. Looks like this is as close as I am going to get for the minute.
Once again thanks.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|