
Getting Network Domain name.
Jeff Hong uses this code. I tested it and it works, but only under NT
Option Explicit
'Author: Jeff Hong YAN
'Date: 12/20/96
'Description: Pass in current user id to get the current domain name and
machine Name
'Works on Windows NT workstation on a Windows NT domain
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
Type WKSTA_USER_INFO_1
wkui1_username As Long
wkui1_logon_domain As Long
wkui1_logon_server As Long
wkui1_oth_domains As Long
End Type
Declare Sub lstrcpyW Lib "kernel32" (dest As Any, ByVal src As Any)
Declare Sub RtlMoveMemory Lib "kernel32" (dest As Any, src As Any, ByVal
size&)
Declare Function NetWkstaGetInfo& Lib "Netapi32" _
(strServer As Any, ByVal lLevel&, pbBuffer As Any)
Declare Function NetWkstaUserGetInfo& Lib "Netapi32" _
(reserved As Any, ByVal lLevel&, pbBuffer As Any)
Declare Function NetApiBufferFree Lib "Netapi32" (ByVal buffer As Long) As
Long
Function GetWorkstationInfo(sDomain As String, sMName As String) As String
Dim lReturn As Long, buffer(512) As Byte
Dim i As Integer
Dim wk101 As WKSTA_INFO_101
Dim pwk101 As Long
Dim wk1 As WKSTA_USER_INFO_1
Dim pwk1 As Long
Dim sUserName As String
Dim sComputerName As String
Dim sLanGroup As String
Dim sLogonDomain As String
sComputerName = "": sLanGroup = "": sUserName = "": sLogonDomain = ""
'Call user defined function (in a another module)
' sUserName = GetUserID()
lReturn = NetWkstaGetInfo(ByVal 0&, 101, pwk101)
RtlMoveMemory wk101, ByVal pwk101, Len(wk101)
lstrcpyW buffer(0), wk101.wki101_computername
i = 0
Do While buffer(i) <> 0
sComputerName = sComputerName & Chr(buffer(i))
i = i + 2
Loop
lstrcpyW buffer(0), wk101.wki101_langroup
i = 0
Do While buffer(i) <> 0
sLanGroup = sLanGroup & Chr(buffer(i))
i = i + 2
Loop
lReturn = NetApiBufferFree(pwk101)
lReturn = NetWkstaUserGetInfo(ByVal 0&, 1, pwk1)
RtlMoveMemory wk1, ByVal pwk1, Len(wk1)
lstrcpyW buffer(0), wk1.wkui1_logon_domain
i = 0
Do While buffer(i) <> 0
sLogonDomain = sLogonDomain & Chr(buffer(i))
i = i + 2
Loop
lReturn = NetApiBufferFree(pwk1)
' Debug.Print sComputerName, sLanGroup, sUserName, sLogonDomain
sMName = sComputerName
sDomain = sLogonDomain
GetWorkstationInfo = sDomain
End Function
Public Function GetDomain() As String
Dim lReturn As Long, buffer(512) As Byte
Dim i As Integer
Dim wk101 As WKSTA_INFO_101
Dim pwk101 As Long
Dim wk1 As WKSTA_USER_INFO_1
Dim pwk1 As Long
Dim sUserName As String
Dim sComputerName As String
Dim sLanGroup As String
Dim sLogonDomain As String
Dim sMName As String
Dim sDomain As String
sComputerName = "": sLanGroup = "": sUserName = "": sLogonDomain = ""
'Call user defined function (in a another module)
' sUserName = GetUserID()
lReturn = NetWkstaGetInfo(ByVal 0&, 101, pwk101)
RtlMoveMemory wk101, ByVal pwk101, Len(wk101)
lstrcpyW buffer(0), wk101.wki101_computername
i = 0
Do While buffer(i) <> 0
sComputerName = sComputerName & Chr(buffer(i))
i = i + 2
Loop
lstrcpyW buffer(0), wk101.wki101_langroup
i = 0
Do While buffer(i) <> 0
sLanGroup = sLanGroup & Chr(buffer(i))
i = i + 2
Loop
lReturn = NetApiBufferFree(pwk101)
lReturn = NetWkstaUserGetInfo(ByVal 0&, 1, pwk1)
RtlMoveMemory wk1, ByVal pwk1, Len(wk1)
lstrcpyW buffer(0), wk1.wkui1_logon_domain
i = 0
Do While buffer(i) <> 0
sLogonDomain = sLogonDomain & Chr(buffer(i))
i = i + 2
Loop
lReturn = NetApiBufferFree(pwk1)
' Debug.Print sComputerName, sLanGroup, sUserName, sLogonDomain
sMName = sComputerName
sDomain = sLogonDomain
GetDomain = sDomain
End Function
Quote:
> Does anyone know the API call that will retrieve the Network Domain name?
> I don't need the Computer name, just the Domain name.
> Thanks for any help.
> --
> SMART Technologies Inc.
> Tim Mayert
> Software Developer
> Tel. 403.228.8552 Fax 403.245.0366
> Visit the SMART Web site: http://www.smarttech.com
> Bringing people and ideas together.