CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Get Server Name

  1. #1
    Join Date
    Oct 1999
    Location
    Sweden
    Posts
    33

    Get Server Name

    Hi!
    How can I get the servername?
    I guess it is with an API but can't find the right one.

    Thanks in advance
    jen


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

    Re: Get Server Name

    what kind of server are you trying to get?
    - NetServerEnum allows you to enumerate all
    servers.
    - NetGetDCName retrieves the name of the domain controller


  3. #3
    Join Date
    Oct 1999
    Location
    Sweden
    Posts
    33

    Re: Get Server Name

    Hi Lothar and thanks for your quick answer!
    I want the Domain Controller but when I search my Win32 via API viewer I can't find this api. What am I doing wrong?
    (I'm using NT 4.0)
    jen


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

    Re: Get Server Name

    >What am I doing wrong?
    Nothing. the API Viewer does not list that function.


    option Explicit
    private Declare Function lstrlenW Lib "kernel32" (byval lpString as Long) as Long
    private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination as Any, Source as Any, byval Length as Long)
    private Declare Function NetGetDCName Lib "Netapi32.dll" (strServer as Any, strDomain as Any, bufptr as Long) as Long
    private Declare Function NetApiBufferFree Lib "Netapi32.dll" (byval lpBuffer as Long) as Long


    private Sub Command1_Click()
    Dim l as Long
    Dim dc() as Byte
    Dim bufptr as Long
    l = NetGetDCName(byval 0&, _
    byval 0&, _
    bufptr)
    MsgBox Pointer2stringw(bufptr)
    NetApiBufferFree bufptr
    End Sub


    private Function Pointer2stringw(byval l as Long) as string
    Dim buffer() as Byte
    Dim nLen as Long
    nLen = lstrlenW(l) * 2
    If nLen then
    ReDim buffer(0 to (nLen - 1)) as Byte
    CopyMemory buffer(0), byval l, nLen
    Pointer2stringw = buffer
    End If
    End Function





    parts of that code abopted from Karl Peterson...



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