Jump to content
Sign in to follow this  
phughes64

Windows Username

Recommended Posts

phughes64

Hi All,

Is there any way that I can capture a user's windows username?

Many thanks

Paul

P.S. sorry if this question has been posted several times before.

Share this post


Link to post
Share on other sites
phughes64

I know how to establish a variable - but how can I pull the username without requiring the user to manually type/select the username?

Share this post


Link to post
Share on other sites
MadBoy

I know how to establish a variable - but how can I pull the username without requiring the user to manually type/select the username?

@username isn't variable in autoit

$variable_name = @username

MsgBox(0,"TEST", $variable_name)
MsgBox(0,"TEST2", @username)

Reason for edit:

Fixed MessageBox to MsgBox. Been using too much C# latly ;)

Edited by MadBoy

My little company: Evotec (PL version: Evotec)

Share this post


Link to post
Share on other sites
Xenobiologist

MsgBox(0, "User Full Name", GetFullName(@UserName))

Func GetFullName($sUserName)
    $colItems = ""
    $strComputer = "localhost"

    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_UserAccount WHERE Name = '" & $sUserName & "'", "WQL", 0x10 + 0x20)

    If IsObj($colItems) Then
        For $objItem In $colItems
            Return $objItem.FullName
        Next
    Else
        Return SetError(1, 0, "")
    EndIf
EndFunc  ;==>GetFullName

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites
Sedorox

MsgBox(0, "User Full Name", GetFullName(@UserName))

Func GetFullName($sUserName)
    $colItems = ""
    $strComputer = "localhost"

    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_UserAccount WHERE Name = '" & $sUserName & "'", "WQL", 0x10 + 0x20)

    If IsObj($colItems) Then
        For $objItem In $colItems
            Return $objItem.FullName
        Next
    Else
        Return SetError(1, 0, "")
    EndIf
EndFunc ;==>GetFullName

Mega

Thanks! I was looking on how to pull username, and then I come across this tidbit. The guy I'm working with and myself were just talking about what to do with grabbing the full name. It's amazing how one can come across this kind of thing! Thanks again!!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.