IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Installation, Déploiement et Sécurité VB Discussion :

[VBA-E] Liste des imprimantes installées


Sujet :

Installation, Déploiement et Sécurité VB

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Février 2004
    Messages
    23
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2004
    Messages : 23
    Points : 16
    Points
    16
    Par défaut [VBA-E] Liste des imprimantes installées
    Bonjour,

    Y a t il possibilité de stocker dans une liste déroulante la liste des imprimantes disponibles ?

  2. #2
    Expert confirmé

    Profil pro
    Inscrit en
    Mai 2005
    Messages
    3 419
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 3 419
    Points : 4 297
    Points
    4 297
    Par défaut
    il foit exister une collection printers

  3. #3
    Inactif  
    Avatar de ouskel'n'or
    Profil pro
    Inscrit en
    Février 2005
    Messages
    12 464
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2005
    Messages : 12 464
    Points : 15 543
    Points
    15 543
    Par défaut
    Regarde à cette adresse
    http://www.developpez.net/forums/viewtopic.php?t=434470

    Si ça ne va pas, tu dis

    A+

  4. #4
    Expert éminent
    Avatar de ThierryAIM
    Homme Profil pro
    Inscrit en
    Septembre 2002
    Messages
    3 673
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2002
    Messages : 3 673
    Points : 8 524
    Points
    8 524
    Par défaut
    le code dans le lien ci-dessu est très imcomplet et mal fichu :

    Je vous livre un mixage de 2 exemples de AllAPI.net :


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    Private Const CCHDEVICENAME = 32
    Private Const CCHFORMNAME = 32
    Private Type DEVMODE
        dmDeviceName As String * CCHDEVICENAME
        dmSpecVersion As Integer
        dmDriverVersion As Integer
        dmSize As Integer
        dmDriverExtra As Integer
        dmFields As Long
        dmOrientation As Integer
        dmPaperSize As Integer
        dmPaperLength As Integer
        dmPaperWidth As Integer
        dmScale As Integer
        dmCopies As Integer
        dmDefaultSource As Integer
        dmPrintQuality As Integer
        dmColor As Integer
        dmDuplex As Integer
        dmYResolution As Integer
        dmTTOption As Integer
        dmCollate As Integer
        dmFormName As String * CCHFORMNAME
        dmUnusedPadding As Integer
        dmBitsPerPel As Integer
        dmPelsWidth As Long
        dmPelsHeight As Long
        dmDisplayFlags As Long
        dmDisplayFrequency As Long
    End Type
     
    Private Type PRINTER_INFO_1
            flags As Long
            pDescription As String
            pName As String
            pComment As String
    End Type
     
    Private Type PRINTER_INFO_2
       pServerName As String
       pPrinterName As String
       pShareName As String
       pPortName As String
       pDriverName As String
       pComment As String
       pLocation As String
       pDevMode As Long
       pSepFile As String
       pPrintProcessor As String
       pDatatype As String
       pParameters As String
       pSecurityDescriptor As Long
       Attributes As Long
       Priority As Long
       DefaultPriority As Long
       StartTime As Long
       UntilTime As Long
       Status As Long
       JobsCount As Long
       AveragePPM As Long
    End Type
    Private Type PRINTER_DEFAULTS
      pDatatype As String
      pDevMode As DEVMODE
      DesiredAccess As Long
    End Type
    Private Declare Function lstrcpy Lib "kernel32.dll" Alias "lstrcpyA" (ByVal lpString1 As String, ByVal lpString2 As Long) As Long
    Private Declare Function lstrlen Lib "kernel32.dll" Alias "lstrlenA" (ByVal lpString As Long) As Long
    Private Declare Function EnumPrinters Lib "winspool.drv" Alias "EnumPrintersA" (ByVal flags As Long, ByVal name As String, ByVal Level As Long, pPrinterEnum As Long, ByVal cdBuf As Long, pcbNeeded As Long, pcReturned As Long) As Long
     
    Const PRINTER_ENUM_LOCAL = &H2
     
    Private Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, pDefault As PRINTER_DEFAULTS) As Long
    Private Declare Function GetPrinter Lib "winspool.drv" Alias "GetPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, buffer As Long, ByVal pbSize As Long, pbSizeNeeded As Long) As Long
    Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
    Private Declare Function IsBadStringPtrByLong Lib "kernel32" Alias "IsBadStringPtrA" (ByVal lpsz As Long, ByVal ucchMax As Long) As Long
     
    Public Function StringFromPointer(lpString As Long, lMaxLength As Long) As String
        Dim sRet As String
        Dim lret As Long
        If lpString = 0 Then
            StringFromPointer = ""
            Exit Function
        End If
        If IsBadStringPtrByLong(lpString, lMaxLength) Then
            ' An error has occured - do not attempt to use this pointer
            StringFromPointer = ""
            Exit Function
        End If
        ' Pre-initialise the return string...
        sRet = Space$(lMaxLength)
        CopyMemory ByVal sRet, ByVal lpString, ByVal Len(sRet)
        If Err.LastDllError = 0 Then
            If InStr(sRet, Chr$(0)) > 0 Then
                sRet = Left$(sRet, InStr(sRet, Chr$(0)) - 1)
            End If
        End If
        StringFromPointer = sRet
    End Function
    Private Sub Form_Load()
        Dim longbuffer() As Long  ' resizable array receives information from the function
        Dim printinfo() As PRINTER_INFO_1  ' values inside longbuffer() will be put into here
        Dim numbytes As Long  ' size in bytes of longbuffer()
        Dim numneeded As Long  ' receives number of bytes necessary if longbuffer() is too small
        Dim numprinters As Long  ' receives number of printers found
        Dim c As Integer, retval As Long  ' counter variable & return value
        Me.AutoRedraw = True 'Set current graphic mode to persistent
        ' Get information about the local printers
        numbytes = 3076  ' should be sufficiently big, but it may not be
        ReDim longbuffer(0 To numbytes / 4) As Long  ' resize array -- note how 1 Long = 4 bytes
        retval = EnumPrinters(PRINTER_ENUM_LOCAL, "", 1, longbuffer(0), numbytes, numneeded, numprinters)
        If retval = 0 Then  ' try enlarging longbuffer() to receive all necessary information
            numbytes = numneeded
            ReDim longbuffer(0 To numbytes / 4) As Long  ' make it large enough
            retval = EnumPrinters(PRINTER_ENUM_LOCAL, "", 1, longbuffer(0), numbytes, numneeded, numprinters)
            If retval = 0 Then ' failed again!
                Debug.Print "Could not successfully enumerate the printes."
            End  ' abort program
        End If
        End If
        ' Convert longbuffer() data into printinfo()
        If numprinters <> 0 Then ReDim printinfo(0 To numprinters - 1) As PRINTER_INFO_1 ' room for each printer
        For c = 0 To numprinters - 1  ' loop, putting each set of information into each element
            ' longbuffer(4 * c) = .flags, longbuffer(4 * c + 1) = .pDescription, etc.
            ' For each string, the string is first buffered to provide enough room, and then the string is copied.
            printinfo(c).flags = longbuffer(4 * c)
            printinfo(c).pDescription = Space(lstrlen(longbuffer(4 * c + 1)))
            retval = lstrcpy(printinfo(c).pDescription, longbuffer(4 * c + 1))
            printinfo(c).pName = Space(lstrlen(longbuffer(4 * c + 2)))
            retval = lstrcpy(printinfo(c).pName, longbuffer(4 * c + 2))
            printinfo(c).pComment = Space(lstrlen(longbuffer(4 * c + 3)))
            retval = lstrcpy(printinfo(c).pComment, longbuffer(4 * c + 3))
        Next c
        ' Display name of each printer
        For c = 0 To numprinters - 1
            GetPrinterInfos (printinfo(c).pName)
        Next c
    End Sub
     
    Sub PrintData(name As String, Data As String)
        If LenB(Data) > 0 Then
            Debug.Print name + ": " + Data
        End If
    End Sub
     
    Private Function GetPrinterInfos(ByVal PrinterName As String) As Long
        Dim SizeNeeded As Long, buffer() As Long
        Dim pDef As PRINTER_DEFAULTS
        'Get a handle to the printer
        lret = OpenPrinter(PrinterName, mhPrinter, pDef)
        'Initialize the buffer
        ReDim Preserve buffer(0 To 0) As Long
        'Retrieve the required size (in bytes)
        lret = GetPrinter(mhPrinter, 2, buffer(0), UBound(buffer), SizeNeeded)
        'Resize the buffer... Note that a Long is four bytes
        ReDim Preserve buffer(0 To (SizeNeeded / 4) + 3) As Long
        'Retrieve the Printer information
        lret = GetPrinter(mhPrinter, 2, buffer(0), UBound(buffer) * 4, SizeNeeded)
        'The data stored in 'buffer' corresponds with the data of a PRINTER_INFO_2 structure
        ClosePrinter mhPrinter
        'Show the data
        PrintData "Server name", StringFromPointer(buffer(0), 255)
        PrintData "Printer name", StringFromPointer(buffer(1), 255)
        PrintData "Share name", StringFromPointer(buffer(2), 255)
        PrintData "Port name", StringFromPointer(buffer(3), 255)
        PrintData "Driver name", StringFromPointer(buffer(4), 255)
        PrintData "Comment", StringFromPointer(buffer(5), 255)
        PrintData "Location", StringFromPointer(buffer(6), 255)
     
    End Function

Discussions similaires

  1. Liste des logiciels installés
    Par Civodul4 dans le forum Windows
    Réponses: 4
    Dernier message: 06/10/2004, 14h51
  2. Comment récupérer la liste des logiciels installés sur une machine ?
    Par david_chardonnet dans le forum API, COM et SDKs
    Réponses: 3
    Dernier message: 19/09/2003, 17h41
  3. Liste des imprimante
    Par billyboy dans le forum Windows
    Réponses: 2
    Dernier message: 17/06/2003, 19h25
  4. Liste des applications installées
    Par Reisubar dans le forum API, COM et SDKs
    Réponses: 7
    Dernier message: 17/05/2003, 13h43
  5. Noms des imprimantes installées
    Par bebeours dans le forum C++Builder
    Réponses: 3
    Dernier message: 06/11/2002, 15h57

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo