NetWork Printer Not getting Displayed in Vb.NET Services
Hi,
I work on VisualStudio 2005 and .NET framework 2.0
I have written the below code and compiled both as Windows application and windows services. The Results are different. I need to run my program as windows services. Please help.
I have added the Reference to Powerpack.Printing.
If I run the below code as windows application, all printers gets listed.
If I run the below code as windows services, NetWork Printers do not get listed.
Any help would be appreciated.
Imports
Microsoft.VisualBasic.PowerPacks.Printing.Compatibility.VB6Public
Sub Listprinters()Dim objPrinterAs PrinterDim strtempAsString =""TryForEach objPrinterIn Printersstrtemp = objPrinter.DeviceName
MessageBox.Show(strtemp)
NextCatch exAs ExceptionMessageBox.Show(ex.ToString())
EndTryEndSub
Thanks for your reply. Well I have local printer connected to my system and also there are network printers. When I run as a windows application, I get all printers ( Local and network ). When I run as a windows services I can see only local printers but network printers do not get displayed.
We have registered our network printers by running at the command promt , \\servername\printer
Thanks once again
Regards
Dhananjaya
how are you registering it? I mean do you do this when you log onto the computer? if so, have you tried to also do this on the network service account, or whatever account the Windows Service is running on, so it can also see it?
Thanks for your reply. I log into the system as network user and register the service as usual installutil <service name>.
I also checked the rights on the printer and all printers have been granted the rights. Not sure what more data i can provide.
Thanks
Regards
Dhananjaya
hmm ok. Do this (wouldnt recommend it)
open the services MMC Snapin (usually in the control panel > administrative tools > Services). Find your service. Double click on it and go to the Log on Tab. Next up change the Log on as to "This Account" and select your user account and enter password, click ok and restart the service. What happens now? does it work?
HI,
I followed the above steps but still the network Printer is not getting displayed. When I run the same method as a windows application, network printer is getting displayed.
Can guide me to any good working examples of Listing down the all printers ( network & local) and printing them as a window services program.
Thanks
Regards
Dhananjaya
well one way is using WMI. add a reference to System.Management and import the System.Management and System.Management.Instrumentation namespaces. Then...
| |
private sub DoShowPrinters() Try Dim searcher As New ManagementObjectSearcher( _ "root\CIMV2", "SELECT DeviceID FROM Win32_Printer") For Each queryObj As ManagementObject in searcher.Get() MessageBox.Show(queryObj("DeviceID").ToString()) Next Catch err As ManagementException MessageBox.Show("An error occurred while querying for WMI data: " & err.Message) End Try end sub
|
this is just one way of getting a list of printers installed on the computer.