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

Windows Discussion :

Récupérer le nom de domaine d'appartenance d'un serveur


Sujet :

Windows

  1. #1
    Rédacteur


    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    7 171
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 7 171
    Points : 15 060
    Points
    15 060
    Billets dans le blog
    1
    Par défaut Récupérer le nom de domaine d'appartenance d'un serveur
    Bonjour,
    j'aimerais savoir comment récupérer le nom de domaine à partir d'un nom de serveur et ce sous NT 4. A partir des informations d'un share par exemple.

    Il existe sous Xp et w2k l'api NetGetJoinInformation :
    The NetGetJoinInformation function retrieves join status information for the specified computer.

    Merci
    Laurent Dardenne

  2. #2
    Membre actif Avatar de seb.49
    Profil pro
    ljgdfgdf
    Inscrit en
    Octobre 2002
    Messages
    291
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France, Maine et Loire (Pays de la Loire)

    Informations professionnelles :
    Activité : ljgdfgdf

    Informations forums :
    Inscription : Octobre 2002
    Messages : 291
    Points : 209
    Points
    209
    Par défaut
    avec quel langage ?

    un exemple

    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
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' Copyright ©1996-2002 VBnet, Randy Birch, All Rights Reserved.
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' You are free to use this code within your own applications,
    ' but you are expressly forbidden from selling or otherwise
    ' distributing this source code without prior written consent.
    ' This includes both posting free demo projects made from this
    ' code as well as reproducing the code in text or html format.
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    Private Const NERR_SUCCESS As Long = 0&
    Private Const MAX_PREFERRED_LENGTH As Long = -1
    
    Private Declare Function NetGetJoinInformation Lib "Netapi32" _
       (ByVal lpServer As Long, _
        lpNameBuffer As Long, _
        BufferType As Long) As Long
    
    Private Declare Function NetApiBufferFree Lib "netapi32.dll" _
       (ByVal Buffer As Long) As Long
    
    Private Declare Sub CopyMemory Lib "kernel32" _
       Alias "RtlMoveMemory" _
      (pTo As Any, uFrom As Any, _
       ByVal lSize As Long)
    
    Private Declare Function lstrlenW Lib "kernel32" _
      (ByVal lpString As Long) As Long
    
    Private Sub Command1_Click()
    
       Dim bufptr          As Long
       Dim dwServer        As Long
       Dim dwBufferType    As Long
       Dim success         As Long
       Dim sServer         As String
    
       sServer = QualifyServer(Environ$("COMPUTERNAME") & vbNullString)
       dwServer = StrPtr(sServer)
    
       success = NetGetJoinInformation(dwServer, _
                                          bufptr, _
                                          dwBufferType)
    
       If (success = NERR_SUCCESS) Then
    
          Print "domain or workgroup  : "; GetPointerToByteStringW(bufptr)
          Print "join status  : "; GetJoinStatus(dwBufferType)
    
       End If
    
       NetApiBufferFree bufptr
    
    End Sub
    
    Private Function GetJoinStatus(dwStatus As Long) As String
    
       Select Case dwStatus
          Case 0: GetJoinStatus = "The status is unknown"
          Case 1: GetJoinStatus = "The computer is not joined"
          Case 2: GetJoinStatus = "The computer is joined to a workgroup"
          Case 3: GetJoinStatus = "The computer is joined to a domain"
          Case Else: GetJoinStatus = "dwStatus outside valid enum range"
       End Select
    
    End Function
    
    Private Function GetPointerToByteStringW(ByVal dwData As Long) As String
    
       Dim tmp() As Byte
       Dim tmplen As Long
    
       If dwData <> 0 Then
    
          tmplen = lstrlenW&#40;dwData&#41; * 2
    
          If tmplen <> 0 Then
    
             ReDim tmp&#40;0 To &#40;tmplen - 1&#41;&#41; As Byte
             CopyMemory tmp&#40;0&#41;, ByVal dwData, tmplen
             GetPointerToByteStringW = tmp
    
         End If
    
       End If
    
    End Function
    
    Private Function QualifyServer&#40;ByVal sServer As String&#41; As String
    
      'see if there are already two slashes
      'preceeding the server name
       If Left$&#40;sServer, 2&#41; = "\\" Then
    
         'there are, so the server is already
         'qualified; return the passed string
          QualifyServer = sServer
    
       Else
    
         'there aren't two, but is there one?
          If Left$&#40;sServer, 1&#41; = "\" Then
    
            'yes, so add one more
             QualifyServer = "\" & sServer
    
          Else
    
            'the string needs both
             QualifyServer = "\\" & sServer
    
          End If  'If Left$&#40;sServer, 1&#41; <> "\"
       End If  'If Left$&#40;sServer, 2&#41; = "\\"
    
    End Function
    de
    Randy Birch
    MVP Visual Basic
    http://www.mvps.org/vbnet/

  3. #3
    Rédacteur


    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    7 171
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 7 171
    Points : 15 060
    Points
    15 060
    Billets dans le blog
    1
    Par défaut
    Bonjour,
    merci pour le code, mais mon PB ne concerne pas la déclaration et l'utilisation de cette API mais plutot qu'elle n'existe pas sous Windows NT4.

    Pour préciser ma question :
    comment simuler cette api ou comment obtenir cette information ( le nom du domaine d'appartenance d'un serveur )?

    Pour le langage j'utilise le Delphi 5.

    Merci
    A+
    Laurent Dardenne

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Récupérer un nom de domaine 'vide', c'est possible ?
    Par Janitrix dans le forum Domaines
    Réponses: 2
    Dernier message: 16/04/2008, 15h09
  2. Réponses: 3
    Dernier message: 27/11/2007, 15h03
  3. C# Récupérer le nom des domaines d'un réseau
    Par EmacLi dans le forum Windows Forms
    Réponses: 3
    Dernier message: 02/08/2006, 08h24
  4. Récupérer le nom de domaine d'un visiteur
    Par Yoshidu62 dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 05/07/2006, 11h54
  5. [C] Récupérer les noms de domaines
    Par Pico10 dans le forum Windows
    Réponses: 12
    Dernier message: 12/03/2006, 23h09

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