Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

[VBA] Nom du groupe de travail réseau

1 réponse
Avatar
HD
Bonjour,

Pour récupérer le nom de domaine de mon réseau, je peux utliser simplement
la variable d'environnement USERDOMAIN via:
MsgBox Environ("USERDOMAIN")
Mais par contre, si je suis sur un réseau ne disposant pas d'un domaine mais
seulement d'un groupe de travail alors la variable USERDOMAIN me ressort le
nom du PC et non le nom du groupe de travail... Existe-t-il une variable
d'environnement qui pourrait me donner le groupe de travail ? Sinon, comment
obtenir ce nom ?

Merci d'avance pour votre aide
--
@+
HD

1 réponse

Avatar
HD
Après quelques recherches... Je suis tombé sur un script qui me ressort Nom
de domaine ET Groupe de travail:

Private Type WKSTA_INFO_101
wki101_platform_id As Long
wki101_computername As Long
wki101_langroup As Long
wki101_ver_major As Long
wki101_ver_minor As Long
wki101_lanroot As Long
End Type

Private Declare Function NetWkstaGetInfo Lib "Netapi32.dll" ( _
lpServer As Any, ByVal Level As Long, lpBuffer As Any) As Long
Private Declare Sub RtlMoveMemory Lib "Kernel32" (dest As Any, _
src As Any, ByVal size&)
Private Declare Sub lstrcpyW Lib "Kernel32" (dest As Any, _
ByVal src As Any)
Private Declare Function NetApiBufferFree& Lib "Netapi32" ( _
ByVal buffer&)

Private Function GetWorkgroup() As String
Dim lResult As Long
Dim pwki101 As Long
Dim wki101 As WKSTA_INFO_101
Dim buffer(512) As Byte
Dim i As Long
Dim LanGroup As String

lResult = NetWkstaGetInfo(ByVal 0&, 101, pwki101)
RtlMoveMemory wki101, ByVal pwki101, Len(wki101)
lstrcpyW buffer(0), wki101.wki101_langroup
i = 0
Do While buffer(i) <> 0
LanGroup = LanGroup & Chr(buffer(i))
i = i + 2
Loop
lResult = NetApiBufferFree(pwk101)

GetWorkgroup = LanGroup
End Function



--
@+
HD