CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 1999
    Posts
    11

    How Do find machine name using API's...

    HI ,

    How do we find out the local machine name and remote machine name using API's in VB .
    I need sample code for calling API's.

    Using Controls,how do find out the machine name(Local/Remote).

    Thanks,

    Sarma Somu

  2. #2
    Join Date
    Apr 1999
    Location
    Rotterdam, Netherlands
    Posts
    278

    Re: How Do find machine name using API's...

    Hi

    For the local computername, copy this to a basfile:

    option Explicit

    private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (byval lpBuffer as string, nSize as Long) as Long
    private Const MAX_COMPUTERNAME_LENGTH = 16 ' 15, but always + 1 for the null terminator


    public Function ComputerName() as string
    Dim sName as string * MAX_COMPUTERNAME_LENGTH
    Dim nSize as Long
    nSize = len(sName)
    If GetComputerName(sName, nSize) <> 0 then
    ' nSize contains on return the no of chars exluding the null char...
    ' so get the left of sName
    ComputerName = Left(sName, nSize)
    else
    ComputerName = ""
    End If
    End Function




    Crazy D :-)


  3. #3
    Join Date
    May 1999
    Posts
    3,332

    Re: How Do find machine name using API's...

    Crazy D told you how to get the local computer name. To get the name of the domain controller, call the NetGetDCName API.


  4. #4
    Join Date
    May 1999
    Posts
    11

    Re: How Do find machine name using API's...

    I got the local system name using the Crazy D code. I need Remote Host( remotesystem ) name .
    To fnd a remote host name ,what type of requirments we need lke IP address , PORT name.
    So i need the code for finding the remote host name.
    I didn't catch the "call the NetGetDCName" point...can you explain briefly..
    Thanks,

    Sarma Somu

  5. #5
    Join Date
    May 1999
    Posts
    3,332

    Re: How Do find machine name using API's...

    honestly, I think I misunderstood your question.
    NetGetDCName would give you the name of the primary domain controller in an NT network. Obviously, that's not what you need.
    Sorry for the confusion.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured