Code Bank
GetPDCName - The name of the Primary Domain Controller
Date: 1/20/2001
Versions: VB4/32 VB5 VB6 Level: Intermediate
Author: The VB2TheMax Team
Private Declare Function NetGetDCName Lib "netapi32.dll" (strServerName As
Any, _
strDomainName As Any, pBuffer As Long) As Long
Private Declare Function NetApiBufferFree Lib "netapi32.dll" (buffer As Any)
As _
Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As
_
Any, source As Any, ByVal bytes As Long)
' Return the name of the Primary Domain Controller (PDC)
'
' server names are preceded by a double slash
Function GetPDCName() As String
Dim lpBuffer As Long
Dim buffer As String
If NetGetDCName(vbNullString, vbNullString, lpBuffer) = 0 Then
' a zero return value means success
buffer = Space$(128)
' copy into local buffer
CopyMemory ByVal StrPtr(buffer), ByVal lpBuffer, LenB(buffer)
' trim excess chars
GetPDCName = Left$(buffer, InStr(buffer & vbNullChar, vbNullChar) -
1)
' release memory
NetApiBufferFree lpBuffer
End If
End Function
Code Bank
ComputerName - The name of the local computer
Date: 4/20/1999
Versions: VB4/32 VB5 VB6 Level: Beginner
Author: The VB2TheMax Team
Private Declare Function GetComputerName Lib "kernel32" Alias _
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
' Returns the name of the computer.
Function ComputerName() As String
Dim buffer As String * 512, length As Long
length = Len(buffer)
If GetComputerName(buffer, length) Then
' this API returns non-zero if successful,
' and modifies the length argument
ComputerName = Left$(buffer, length)
End If
End Function
Code Bank
NetworkUserName - The user name used to establish a network connection
Date: 1/20/2001
Versions: VB4/32 VB5 VB6 Level: Intermediate
Author: The VB2TheMax Team
Private Declare Function WNetGetUser Lib "mpr.dll" Alias "WNetGetUserA"
(ByVal _
lpszLocalName As String, ByVal lpszUserName As String, _
lpcchBuffer As Long) As Long
' return the current default user name or
' the user name used to establish a connection
Function NetworkUserName() As String
Dim buffer As String
buffer = Space$(256)
' if the WNetGetUser API returns 0, then
' the user name is in buffer
If WNetGetUser(vbNullString, buffer, Len(buffer)) = 0 Then
NetworkUserName = Left$(buffer, InStr(buffer, vbNullChar) - 1)
End If
End Function
-----Original Message-----
From: Tim Mccurdy [mailto:tmccurdy@c...]
Sent: 18 April 2001 14:05
To: professional vb
Subject: [pro_vb] Re: How to find out whether the Computer is in netwo
rk
Use the WinSock control and PING the PC Name.
-----Original Message-----
From: vinay.poddar@s... [mailto:vinay.poddar@s...]
Sent: Wednesday, April 18, 2001 8:28 AM
To: professional vb
Subject: [pro_vb] Re: How to find out whether the Computer is in network
Hi,
I also want to know answer of this question.
Vinay