Getting Domain name 
Author Message
 Getting Domain name

I was wondering if VB5 had any internal commands to get a domain name, if
not, what would be the API calls?

---------------------------
Michael Feldblyum
HealthNetwork
---------------------------



Fri, 22 Oct 1999 03:00:00 GMT  
 Getting Domain name

Quote:

> I was wondering if VB5 had any internal commands to get a domain name, if
> not, what would be the API calls?

> ---------------------------
> Michael Feldblyum
> HealthNetwork
> ---------------------------

The following is a reposting.

4/5/97

Hi all,

The following is the function I use to get the current logon domain name and machine
name. There could be many ways to get the current machine name (from registry, calling
WNet* function, etc..). This posting employs NetWksta* API function set.

I welcome any comments and suggestions.

Rgds
Jeff Hong YAN

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 Boolean

    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

End Function



Sat, 23 Oct 1999 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Getting domain name of parent domain

2. Getting Domain Name

3. Getting Domain Name

4. API for getting domain names from VB6

5. Getting name from Domain Name Server in VB?

6. Getting the Domain Name

7. Getting user names on NT domain

8. Getting user names of the same domain.

9. Getting the NETBIOS name of a DNS-style domain

10. Getting Network Domain name.

11. Getting Domain Controller Name

12. Getting The Full Domain User Name In Win95

 

 
Powered by phpBB® Forum Software