Desktop Functions:

   Smart Device Functions:

Show Recent Changes
Subscribe (RSS)
Misc. Pages
Helpful Tools
Suggested Reading
Website TODO List
Support Forum
Download Visual Studio Add-In

Terms of Use
Privacy Policy
NetWkstaUserGetInfo (netapi32)
Returns information about the currently logged-on user. This function must be called in the context of the logged-on user.

C# Signature:

[DllImport("netapi32.dll", SetLastError=true)]
static extern int NetWkstaUserGetInfo(
    [MarshalAs(UnmanagedType.LPWStr)]string reserved,
    int level, out IntPtr lpBuffer);

VB Signature:

Declare Function NetWkstaUserGetInfo Lib "netapi32.dll" (ByVal reserved As String, ByVal level As Integer, ByRef lpBuffer As IntPtr) As Integer

User-Defined Types:

public struct WKSTA_USER_INFO_1
    public string wkui1_username;

    public string wkui1_logon_domain;

    public string wkui1_oth_domains;

    public string wkui1_logon_server;

Alternative Managed API:

Do you know one? Please contribute it!



Tips & Tricks:

Please add some!

Sample Code:

    Private Sub GetLoggedInUserInfo()
        Dim lpBuffer As IntPtr
        Dim result As Integer = NetWkstaUserGetInfo(Nothing, 1, lpBuffer)
        If result = 0 Then
            Dim wksInfo As WKSTA_USER_INFO_1 = Marshal.PtrToStructure(lpBuffer, GetType(WKSTA_USER_INFO_1))
            ''' Do something
        End If
    End Sub

C# Sample

/// <summary>
/// Retrieves the default domain for the currently logged in user.
/// </summary>
/// <returns>The name of the domain currently logged into.</returns>
public static string GetDefaultDomain()
    IntPtr buffer = new IntPtr();
    string domain = "";
    int result;
    WKSTA_USER_INFO_1 wksInfo;

    result = NetWkstaUserGetInfo(null, 1, out buffer);
    if (result == 0)
        wksInfo = (WKSTA_USER_INFO_1)Marshal.PtrToStructure(
            buffer, typeof(WKSTA_USER_INFO_1));

        domain = wksInfo.wkui1101_logon_domain;

    return domain;

Please add some more!


Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

Access directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version