Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than netapi32, prefix the name with the module name and a period.
NetWkstaUserGetInfo (netapi32)
.
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:
[StructLayout(LayoutKind.Sequential)]
public struct WKSTA_USER_INFO_1
{
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]
public string wkui1_username;
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]
public string wkui1_logon_domain;
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]
public string wkui1_oth_domains;
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]
public string wkui1_logon_server;
}
Alternative Managed API:
Do you know one? Please contribute it!
Notes:
None.
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
NetApiBufferFree(lpBuffer)
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));
Int32 pointer = buffer.ToInt32();
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).