• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 183
  • Last Modified:

ComputerNames and DNS name

Does anybody know how I can find out the local Comp.Name
and DNS name under VB4 ????
  • 3
  • 2
  • 2
1 Solution
'get the user name of the computer
'put this in your bas module
Public Declare Function GetComputerName Lib _
"kernel32" Alias "GetComputerNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long

Public Function sGetComputerName() As String
  Dim sBuffer As String
  Dim lBufSize As Long
  Dim lStatus As Long
  lBufSize = 255
  sBuffer = String$(lBufSize, " ")
  lStatus = GetComputerName(sBuffer, lBufSize)
  sGetComputerName = ""
  If lStatus <> 0 Then
     sGetComputerName = Left(sBuffer, lBufSize)
  End If
  Form1.Label2 = sGetComputerName
End Function

'put this in the click event (load...whatever)
      Dim x
      x = sGetComputerName
'get the Window's username of system
'Make a new project. Add a module.
'To the form add a label.

'Add this code to the module:

Declare Function GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) _
As Long

'this is form load

Dim s As String
Dim cnt As Long
Dim dl As Long
Dim CurUser As String
cnt = 199
s = String$(200, 0)
dl = GetUserName(s, cnt)
If dl <> 0 Then CurUser = Left$(s, cnt) Else CurUser = ""
msgbox  CurUser

Getting the I.P for a Given URL/Computer/Server Name..

Add a Command Button and 2 Textboxes to a Form..

Private Const MAX_WSADescription = 256
Private Const MAX_WSASYSStatus = 128
Private Const WS_VERSION_REQD = &H101
Private Type HOSTENT
   hName As Long
   hAliases As Long
   hAddrType As Integer
   hLen As Integer
   hAddrList As Long
End Type
Private Type WSADATA
   wVersion As Integer
   wHighVersion As Integer
   szDescription(0 To MAX_WSADescription) As Byte
   szSystemStatus(0 To MAX_WSASYSStatus) As Byte
   wMaxSockets As Integer
   wMaxUDPDG As Integer
   dwVendorInfo As Long
End Type
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, ByVal hpvSource As Long, ByVal cbCopy As Long)
Private Declare Function gethostbyname Lib "WSOCK32.DLL" (ByVal szHost As String) As Long
Private Declare Function WSAStartup Lib "WSOCK32.DLL" (ByVal wVersionRequired As Long, lpWSADATA As WSADATA) As Long
Private Declare Function WSACleanup Lib "WSOCK32.DLL" () As Long
Private Function GetIPAddress(ByVal sHost As String) As String
    Dim I As Integer
    Dim lHost As Long
    Dim lIP As Long
    Dim sIP() As Byte
    Dim sFullIP As String
    Dim tHost As HOSTENT
    Dim tSocket As WSADATA
    'Establish an Open Socket
    If WSAStartup(WS_VERSION_REQD, tSocket) <> 0 Then Exit Function
    'Attempt to Locate Data pointer for Specified Host Name
    lHost = gethostbyname(sHost)
    If lHost = 0 Then
        MsgBox "Unable to Locate Host."
        'Get the Host Info
        CopyMemory tHost, lHost, Len(tHost)
        'Extract the Address of the IP Data from the Addresslist Pointer
        CopyMemory lIP, tHost.hAddrList, Len(tHost.hAddrList)
        'Build a Tempory array to hold the IP Values
        ReDim sIP(tHost.hLen - 1)
        'Copy the IP Values into the Array
        CopyMemory sIP(0), lIP, tHost.hLen
        'Build the IP Address
        For I = 0 To tHost.hLen - 1
            sFullIP = sFullIP & "." & sIP(I)
        'Trim of the Preceeding Period
        GetIPAddress = Mid(sFullIP, 2)
    End If
    'Close up the Socket
    Call WSACleanup
End Function
Private Sub Command1_Click()
    Text2 = GetIPAddress(Text1)
End Sub
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

MatthiasKAuthor Commented:
Great, that helps. Is there a way for the Domain Name as
well ???
MatthiasKAuthor Commented:
I'm looking more for local name resolution eg DNS and
Someone answered to the similiar question..


If this is not what you are looking for, please let me know and I will work on it.
MatthiasKAuthor Commented:
The other answer is for DSN's I believe thats not
for the local Domain Name.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now