Récupération du Hostname local d'un poste
Source / Exemple :
' code à placer dans un module
Public Type WSADATA
wVersion As Integer
wHighVersion As Integer
szDescription As String * 257
szSystemStatus As String * 129
iMaxSockets As Long
iMaxUdpDg As Long
lpVendorInfo As Long
End Type
' API
Public Declare Function gethostname Lib "wsock32.dll" (ByVal name As String, ByVal namelen As Long) As Long
Public Declare Function WSAStartup Lib "wsock32.dll" (ByVal wVersionRequested As Integer, lpWSAData As WSADATA) As Long
Public Declare Function WSACleanup Lib "wsock32.dll" () As Long
Public Function MAKEWORD(ByVal bLow As Byte, ByVal bHigh As Byte) As Integer
MAKEWORD = Val("&H" & Right("00" & Hex(bHigh), 2) & Right("00" & Hex(bLow), 2))
End Function
' code à placer dans une Form
Private Sub Form_Load()
Dim slocalhostName As String
Dim retval As Long
Dim sockinfo As WSADATA
' ouvrir une Winsock session
retval = WSACleanup()
retval = WSAStartup(MAKEWORD(2, 2), sockinfo)
If retval <> 0 Then
MsgBox "Erreur sur chargement Winsock !"
Exit Sub
End If
slocalhostName = Space(256)
retval = gethostname(slocalhostName, 256)
txtHostName = Left$(slocalhostName, InStr(slocalhostName, vbNullChar) - 1)
End Sub
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.