|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
PRINTER INFORMATIONI use the code below to find the printers connected to the local computer. How can I get the "Location" and "Description" information from the printers I have connected? Public Sub EnumerateConnectedPrinters(ByVal objECP As System.Collections.Generic.List(Of String)) Dim strPrinter As String Try objECP.Clear() For Each strPrinter In PrinterSettings.InstalledPrinters 'How can I find LOCATION and DESCRIPTION on a connected printer If CBool(InStr(1, strPrinter, "\\", Microsoft.VisualBasic.CompareMethod.Text)) Then objECP.Add(Split(strPrinter, "\")(3) & "," & Split(strPrinter, "\")(2) & ",,") Else objECP.Add(strPrinter & ",,,") End If Next strPrinter Catch ex As Exception 'If bDebug Then Console.WriteLine("Error - Failed when disconnecting network printers.") logfile.WriteLine("Error - Failed to enumerate connected printers.") logfile.Flush() Finally strPrinter = Nothing End Try End Sub Regards Morten Fagermoen Hi,
You need to use the wmi to get more info. 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} - {1} - {2}", mo("Name"), mo("location"), mo("description")) Trace.WriteLine(strOut) Next Ken ----------------------------------------- Show quoteHide quote "Morten Fagermoen" wrote: > Hi! > > I use the code below to find the printers connected to the local computer. > > How can I get the "Location" and "Description" information from the printers > I have connected? > > > Public Sub EnumerateConnectedPrinters(ByVal objECP As > System.Collections.Generic.List(Of String)) > Dim strPrinter As String > Try > objECP.Clear() > For Each strPrinter In PrinterSettings.InstalledPrinters > 'How can I find LOCATION and DESCRIPTION on a connected printer > If CBool(InStr(1, strPrinter, "\\", > Microsoft.VisualBasic.CompareMethod.Text)) Then > objECP.Add(Split(strPrinter, "\")(3) & "," & > Split(strPrinter, "\")(2) & ",,") > Else > objECP.Add(strPrinter & ",,,") > End If > Next strPrinter > Catch ex As Exception > 'If bDebug Then Console.WriteLine("Error - Failed when disconnecting > network printers.") > logfile.WriteLine("Error - Failed to enumerate connected printers.") > logfile.Flush() > Finally > strPrinter = Nothing > End Try > End Sub > > > > Regards > > Morten Fagermoen > > Hi, again!
This worked fine. Thank you very much, Ken!! Morten Show quoteHide quote "Ken Tucker [MVP]" <KenTucker***@discussions.microsoft.com> wrote in message news:CE90F881-7674-441A-96B1-4E38D6C181C4@microsoft.com... > Hi, > > You need to use the wmi to get more info. 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} - {1} - {2}", mo("Name"), > mo("location"), mo("description")) > Trace.WriteLine(strOut) > Next > > > Ken > ----------------------------------------- > > "Morten Fagermoen" wrote: > >> Hi! >> >> I use the code below to find the printers connected to the local >> computer. >> >> How can I get the "Location" and "Description" information from the >> printers >> I have connected? >> >> >> Public Sub EnumerateConnectedPrinters(ByVal objECP As >> System.Collections.Generic.List(Of String)) >> Dim strPrinter As String >> Try >> objECP.Clear() >> For Each strPrinter In PrinterSettings.InstalledPrinters >> 'How can I find LOCATION and DESCRIPTION on a connected >> printer >> If CBool(InStr(1, strPrinter, "\\", >> Microsoft.VisualBasic.CompareMethod.Text)) Then >> objECP.Add(Split(strPrinter, "\")(3) & "," & >> Split(strPrinter, "\")(2) & ",,") >> Else >> objECP.Add(strPrinter & ",,,") >> End If >> Next strPrinter >> Catch ex As Exception >> 'If bDebug Then Console.WriteLine("Error - Failed when >> disconnecting >> network printers.") >> logfile.WriteLine("Error - Failed to enumerate connected >> printers.") >> logfile.Flush() >> Finally >> strPrinter = Nothing >> End Try >> End Sub >> >> >> >> Regards >> >> Morten Fagermoen >> >> You can also use the windows API.
e.g. GetPrinter , EnumPrinters etc. There is a component wrapper called PrintQueueWatch.NET for this and other printer API calls on my website and on the CodePlex site (http://www.codeplex.com/PUMA) Show quoteHide quote "Morten Fagermoen" <mor***@fagermoen.com> wrote in message news:etdoqv0CHHA.5068@TK2MSFTNGP02.phx.gbl... > Hi, again! > > This worked fine. > > Thank you very much, Ken!! > > Morten > > > "Ken Tucker [MVP]" <KenTucker***@discussions.microsoft.com> wrote in > message news:CE90F881-7674-441A-96B1-4E38D6C181C4@microsoft.com... >> Hi, >> >> You need to use the wmi to get more info. 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} - {1} - {2}", mo("Name"), >> mo("location"), mo("description")) >> Trace.WriteLine(strOut) >> Next >> >> >> Ken >> ----------------------------------------- >> >> "Morten Fagermoen" wrote: >> >>> Hi! >>> >>> I use the code below to find the printers connected to the local >>> computer. >>> >>> How can I get the "Location" and "Description" information from the >>> printers >>> I have connected? >>> >>> >>> Public Sub EnumerateConnectedPrinters(ByVal objECP As >>> System.Collections.Generic.List(Of String)) >>> Dim strPrinter As String >>> Try >>> objECP.Clear() >>> For Each strPrinter In PrinterSettings.InstalledPrinters >>> 'How can I find LOCATION and DESCRIPTION on a connected >>> printer >>> If CBool(InStr(1, strPrinter, "\\", >>> Microsoft.VisualBasic.CompareMethod.Text)) Then >>> objECP.Add(Split(strPrinter, "\")(3) & "," & >>> Split(strPrinter, "\")(2) & ",,") >>> Else >>> objECP.Add(strPrinter & ",,,") >>> End If >>> Next strPrinter >>> Catch ex As Exception >>> 'If bDebug Then Console.WriteLine("Error - Failed when >>> disconnecting >>> network printers.") >>> logfile.WriteLine("Error - Failed to enumerate connected >>> printers.") >>> logfile.Flush() >>> Finally >>> strPrinter = Nothing >>> End Try >>> End Sub >>> >>> >>> >>> Regards >>> >>> Morten Fagermoen >>> >>> >
Syntax error in INSERT INTO statement
How to attach an exe to the debugger? question about opening SQL results in Excel from ASP.NET via XML User Control saving properties Newbie - MDI Question byte array concatenation Getting the generated name attribute for use in JavaScript problem with DataSet.GetXml() method syntax to compare data from text field, when adding a record, to a field in a table for duplicates Blinking button |
|||||||||||||||||||||||