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 advapi32, prefix the name with the module name and a period.
<DllImport("advapi32.dll", EntryPoint:="GetUserNameW", SetLastError:=True)> _
Public Function GetUserName(<MarshalAs(UnmanagedType.LPTSTR)>System.Text.StringBuilder sb, _
ByRef length As Integer) As <MarshalAs(UnmanagedType.Bool)>Boolean
End Function
VB Signature:
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, ByRef nMax As Integer) As Boolean
User-Defined Types:
None.
Alternative Managed API:
Environment.UserName (System.Environment)
Notes:
None.
Tips & Tricks:
Please add some!
Sample Code:
using System;
using System.Text;
using System.Runtime.InteropServices;
namespace GetUserNameExample
{
class Class1
{
[DllImport("Advapi32.dll")]
static extern bool GetUserName(StringBuilder lpBuffer, ref int nSize);
[STAThread]
static void Main(string[] args)
{
StringBuilder Buffer = new StringBuilder(64);
int nSize=64;
GetUserName(Buffer, ref nSize);
Console.WriteLine(Buffer.ToString());
}
}
}
Sample Code (VB.NET):
Imports System
Imports System.Text
Imports System.Runtime.InteropServices
Namespace GetUserNameExample
Class Class1
<DllImport("advapi32.dll", EntryPoint:="GetUserNameA", SetLastError:=True)> _
Public Function GetUserName(<MarshalAs(UnamagedType.LPTSTR)>System.Text.StringBuilder sb, _
ByRef length As Integer) As <MarshalAs(UnmanagedType.Bool)>Boolean
End Function
<STAThread> _
Public Sub Main()
Dim Buffer = new StringBuilder(64)
Dim nSize As Integer =64
GetUserName(Buffer, nSize)
Console.WriteLine(Buffer.ToString())
End Sub
End Class
End Namespace
Sample Code (VB):
Dim xstr as String = Space(255)
Dim max as Integer = 255
Dim rc as Integer
rc = GetUserName(xstr,max)
' max will now contain the total number of
' characters written to the buffer (here: xstr)
MessageBox.Show(Mid(xstr,1,max))
The GetUserName function retrieves the name of the user associated with the current thread.
11/7/2014 12:08:30 AM - -122.170.55.192
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).