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

VBA Access Discussion :

récupérer adresse IP d'une imprimante réseau


Sujet :

VBA Access

  1. #1
    Futur Membre du Club
    Inscrit en
    Juin 2002
    Messages
    10
    Détails du profil
    Informations forums :
    Inscription : Juin 2002
    Messages : 10
    Points : 9
    Points
    9
    Par défaut récupérer adresse IP d'une imprimante réseau
    Bonsoir,
    dans une application ACCESS 200à en VBA je récupère le nom et le port d'une imprimante réseau : c'est OK pour le nom de l'imprimante mais le nom du port est NE00: à chaque alors ce qui m'interesse c'est le nom du port IP_XXX
    .XXX. etc ... avec IP ( imprimante par défaut WINDOWS ).
    Quelq'un a t il déjà réussi à récupérer le nom du port d'une imprimante réseau ?
    ( j'ai tenté en passant par le DNS name mais les imprimantes du réseau ne sont pas dans le DNS ici ).

    d'avance merci.

    Anonymkim

  2. #2
    Membre chevronné

    Profil pro
    Inscrit en
    Avril 2006
    Messages
    1 399
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 1 399
    Points : 2 221
    Points
    2 221
    Par défaut
    Bonjour,

    pourtant, le code suivant retourne bien chez moi l'adresse IP de l'imprimante par défaut (en réseau) :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
     
    MsgBox Application.Printer.Port
    Je pense que vous procédez comme ça ?

    Philippe

    J'ai lu ça sur le web, ça peut aider à comprendre :
    http://technet2.microsoft.com/Window....mspx?mfr=true

  3. #3
    Futur Membre du Club
    Inscrit en
    Juin 2002
    Messages
    10
    Détails du profil
    Informations forums :
    Inscription : Juin 2002
    Messages : 10
    Points : 9
    Points
    9
    Par défaut Oui mais ACCESS 2000
    apparemment ne gère pas l'objet Printer donc je suis passé par le KERNEL32 !

    Y a t il une librairie à ajouter pour avoir cet objet Printer ?

    D'avance merci.

  4. #4
    Membre chevronné

    Profil pro
    Inscrit en
    Avril 2006
    Messages
    1 399
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 1 399
    Points : 2 221
    Points
    2 221
    Par défaut
    Bonjour,

    essayez ce code, il devrait afficher toutes vos imprimantes :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
     
    Dim oPrt As Printer
     
    For Each oPrt In Application.Printers
       With oPrt
        MsgBox "Device name: " & .DeviceName & vbCrLf _
             & "Driver name: " & .DriverName & vbCrLf & "Port: " & .Port
       End With
    Next oPrt
    Philippe

  5. #5
    Membre émérite

    Profil pro
    Inscrit en
    Février 2005
    Messages
    1 751
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2005
    Messages : 1 751
    Points : 2 368
    Points
    2 368
    Par défaut
    Bonjour,
    Citation Envoyé par anonymkim
    apparemment ne gère pas l'objet Printer donc je suis passé par le KERNEL32 !

    Y a t il une librairie à ajouter pour avoir cet objet Printer ?
    La collection Printers et les objets Printer n'existent pas dans Access 2000 .

  6. #6
    Membre chevronné

    Profil pro
    Inscrit en
    Avril 2006
    Messages
    1 399
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 1 399
    Points : 2 221
    Points
    2 221
    Par défaut
    Bonjour,

    Merci pour la précision...

    Bon ben il faut passer a priori par les APIs.

    En surfant, j'ai trouvé ça, sans garantie, et il y a peut-être plus simple, même dans la FAQ ?

    C'est une base de travail, à adapter...

    Site : http://www.merrioncomputing.com/

    Dans un module standard écrire :
    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
     
     
    ' http://www.merrioncomputing.com/
    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_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
     
    Public Enum Printer_Status
       PRINTER_STATUS_READY = &H0
       PRINTER_STATUS_PAUSED = &H1
       PRINTER_STATUS_ERROR = &H2
       PRINTER_STATUS_PENDING_DELETION = &H4
       PRINTER_STATUS_PAPER_JAM = &H8
       PRINTER_STATUS_PAPER_OUT = &H10
       PRINTER_STATUS_MANUAL_FEED = &H20
       PRINTER_STATUS_PAPER_PROBLEM = &H40
       PRINTER_STATUS_OFFLINE = &H80
       PRINTER_STATUS_IO_ACTIVE = &H100
       PRINTER_STATUS_BUSY = &H200
       PRINTER_STATUS_PRINTING = &H400
       PRINTER_STATUS_OUTPUT_BIN_FULL = &H800
       PRINTER_STATUS_NOT_AVAILABLE = &H1000
       PRINTER_STATUS_WAITING = &H2000
       PRINTER_STATUS_PROCESSING = &H4000
       PRINTER_STATUS_INITIALIZING = &H8000
       PRINTER_STATUS_WARMING_UP = &H10000
       PRINTER_STATUS_TONER_LOW = &H20000
       PRINTER_STATUS_NO_TONER = &H40000
       PRINTER_STATUS_PAGE_PUNT = &H80000
       PRINTER_STATUS_USER_INTERVENTION = &H100000
       PRINTER_STATUS_OUT_OF_MEMORY = &H200000
       PRINTER_STATUS_DOOR_OPEN = &H400000
       PRINTER_STATUS_SERVER_UNKNOWN = &H800000
       PRINTER_STATUS_POWER_SAVE = &H1000000
    End Enum
     
    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
     
    Public Sub GetPrinterInfos(sPrinterName As String)
        Dim mhPrinter As Long, lRet As Long
        Dim SizeNeeded As Long, buffer() As Long
        Dim pDef As PRINTER_DEFAULTS
        'Get a handle to the printer
        lRet = OpenPrinter(sPrinterName, 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 Sub
     
    Private Sub PrintData(Name As String, Data As String)
        If LenB(Data) > 0 Then
            Debug.Print Name + ": " + Data
        End If
    End Sub
    En appelant la fonction GetPrinterInfos ("NomDeMonImprimante"), la fonction affiche dans la fenetre execution de VBA via debug.print les infos de l'imprimante.

    Exemple personnel :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
     
    GetPrinterInfos ("HP DeskJet 895Cxi (Lan)")
    et j'obtiens :

    Printer name: HP DeskJet 895Cxi (Lan)
    Port name: IP_192.168.0.2
    Driver name: HP DeskJet 895Cxi



    Je pense que d'autre personnes ont le même problème que vous sous Access 2000 et ils vont surement pouvoir mieux vous répondre que moi.


    Philippe

Discussions similaires

  1. Envoyer une impression vers une imprimante réseau sous DOS
    Par atasekpo dans le forum Administration
    Réponses: 3
    Dernier message: 28/06/2010, 15h58
  2. Connecter automatiquement une imprimante réseau disponible sur un domaine
    Par NicolasJolet dans le forum Autres Logiciels
    Réponses: 11
    Dernier message: 17/10/2006, 16h11
  3. Sélection d'une imprimante réseau
    Par tagada le hun dans le forum Powerbuilder
    Réponses: 2
    Dernier message: 21/08/2006, 16h05
  4. Récupérer adresse url d'une frame a partir d'une autre
    Par ok07 dans le forum Général JavaScript
    Réponses: 10
    Dernier message: 08/08/2006, 23h53
  5. Accéder à une imprimante réseau sans identification
    Par bart64 dans le forum Windows Serveur
    Réponses: 3
    Dernier message: 01/08/2006, 13h14

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