Click here to Skip to main content
15,927,699 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionWeek Number from MonthCalender Pin
Bright267729-Jun-07 20:46
Bright267729-Jun-07 20:46 
AnswerRe: Week Number from MonthCalender Pin
Ajai Chaudhary29-Jun-07 21:07
Ajai Chaudhary29-Jun-07 21:07 
GeneralRe: Week Number from MonthCalender Pin
Guffa30-Jun-07 7:46
Guffa30-Jun-07 7:46 
AnswerRe: Week Number from MonthCalender Pin
Guffa30-Jun-07 7:43
Guffa30-Jun-07 7:43 
QuestionEnumerating Network Printers Pin
xbiplav29-Jun-07 19:48
xbiplav29-Jun-07 19:48 
AnswerRe: Enumerating Network Printers Pin
Duncan Edwards Jones30-Jun-07 1:22
professionalDuncan Edwards Jones30-Jun-07 1:22 
QuestionRe: Enumerating Network Printers Pin
xbiplav30-Jun-07 5:08
xbiplav30-Jun-07 5:08 
AnswerRe: Enumerating Network Printers Pin
Duncan Edwards Jones30-Jun-07 6:19
professionalDuncan Edwards Jones30-Jun-07 6:19 
I have all this stuff built into a fairly large object model so it is a bit difficult to cut out just the bits that are needed, but it should look something a bit like:

VB
Dim pcbNeeded As Int32 '\\ Holds the requires size of the output buffer (in bytes)
Dim pcReturned As Int32 '\\ Holds the returned size of the output buffer
Dim pPrinters As IntPtr
Dim pcbProvided As Int32 = 0

If Not EnumPrinters(EnumPrinterFlags.PRINTER_ENUM_NETWORK, String.Empty, 1, pPrinters, 0, pcbNeeded, pcReturned) Then
    If pcbNeeded > 0 Then
        pPrinters = Marshal.AllocHGlobal(pcbNeeded)
        pcbProvided = pcbNeeded
        If Not EnumPrinters(EnumPrinterFlags.PRINTER_ENUM_NETWORK, String.Empty, 1, pPrinters, pcbProvided, pcbNeeded, pcReturned) Then
            Throw New Win32Exception
        End If
    End If
End If

If pcReturned > 0 Then
    '\\ Get all the printers for the given server
    Dim ptNext As IntPtr = pPrinters
    While pcReturned > 0
        Dim pi1 As New PRINTER_INFO_1
        Marshal.PtrToStructure(ptNext, pi1)
        If Not pi1.pPrinterName Is Nothing Then
           'Found a printer on the network...
        End If
        ptNext = New IntPtr(ptNext.ToInt32 + Marshal.SizeOf(pi1))
        pcReturned -= 1
    End While
End If

'\\ Free the allocated buffer memory
If pPrinters.ToInt32 > 0 Then
    Marshal.FreeHGlobal(pPrinters)
End If


However there's probably loads of declarations and namespaces missing from that - your best bet would be to download the latest source code form the printer usage monitoring application[^] and cut the bits you need out of that.

There is also more info on Randy Birch's site here[^]



'--8<------------------------
Ex Datis:
Duncan Jones
Merrion Computing Ltd

GeneralRe: Enumerating Network Printers Pin
xbiplav30-Jun-07 6:28
xbiplav30-Jun-07 6:28 
QuestionDLL REGISTRATION Pin
saurabhshri29-Jun-07 19:36
saurabhshri29-Jun-07 19:36 
AnswerRe: DLL REGISTRATION Pin
Ajai Chaudhary29-Jun-07 19:43
Ajai Chaudhary29-Jun-07 19:43 
AnswerRe: DLL REGISTRATION Pin
Christian Graus29-Jun-07 23:43
protectorChristian Graus29-Jun-07 23:43 
QuestionHow to attach a word tamplate in existing file. Pin
Ajai Chaudhary29-Jun-07 19:34
Ajai Chaudhary29-Jun-07 19:34 
QuestionCrystal Report Pin
saurabhshri29-Jun-07 19:29
saurabhshri29-Jun-07 19:29 
AnswerRe: Crystal Report Pin
klaydze29-Jun-07 23:17
klaydze29-Jun-07 23:17 
QuestionInstalling Application Pin
nitin_ion29-Jun-07 19:15
nitin_ion29-Jun-07 19:15 
AnswerRe: Installing Application Pin
Christian Graus29-Jun-07 23:49
protectorChristian Graus29-Jun-07 23:49 
QuestionBackground Processing Pin
Ajai Chaudhary29-Jun-07 18:58
Ajai Chaudhary29-Jun-07 18:58 
AnswerRe: Background Processing Pin
Christian Graus29-Jun-07 23:50
protectorChristian Graus29-Jun-07 23:50 
QuestionShutdowning your computer Pin
klaydze29-Jun-07 18:19
klaydze29-Jun-07 18:19 
AnswerRe: Shutdowning your computer Pin
ips_sun29-Jun-07 20:42
ips_sun29-Jun-07 20:42 
GeneralRe: Shutdowning your computer Pin
Ajai Chaudhary29-Jun-07 20:49
Ajai Chaudhary29-Jun-07 20:49 
GeneralRe: Shutdowning your computer Pin
klaydze29-Jun-07 23:12
klaydze29-Jun-07 23:12 
GeneralRe: Shutdowning your computer Pin
klaydze29-Jun-07 23:08
klaydze29-Jun-07 23:08 
QuestionMs Access password Viewer Pin
bluesperrow29-Jun-07 11:46
bluesperrow29-Jun-07 11:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.