Jump to content

Windows Username


Recommended Posts

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)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!!
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...