Created
February 19, 2015 00:55
-
-
Save blacksun1/9c23aa43ad49f640b49e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-UsersFullName { | |
$NAME_DISPLAY = [int] 3 | |
$MethodDefinition = @' | |
[DllImport("secur32.dll", CharSet=CharSet.Auto, SetLastError=true)] | |
[return: MarshalAs(UnmanagedType.I1)] | |
public static extern int GetUserNameEx (int nameFormat, StringBuilder userName, ref UInt32 userNameSize); | |
'@ | |
$type = Add-Type -MemberDefinition $MethodDefinition ` | |
-NameSpace Win32 -Name "Secur32" ` | |
-Using "System.Text" -PassThru | |
$sb = New-Object -TypeName "System.Text.StringBuilder" -ArgumentList 1024 | |
$rv = [int]([Win32.Secur32]::GetUserNameEx($NAME_DISPLAY, $sb, [ref][UInt32]($sb.Capacity))) | |
return $sb.ToString() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code doesn't work yet. I get the following...