@msdn=http://search.microsoft.com/search/results.aspx?qu=$$$ @pinvoke=http://pinvoke.net/$$$.htm Summary: 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: [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)); domain = wksInfo.wkui1101_logon_domain; System.Windows.Forms.MessageBox.Show(domain); NetApiBufferFree(buffer); } return domain; } Please add some more! Documentation: NetWkstaUserGetInfo@msdn on MSDN
Edit netapi32.NetWksta...
You do not have permission to change this page. If you feel this is in error, please send feedback with the contact link on the main page.