# Name issues.

## Recommended Posts

I'm troubled by a little issue regarding user name.

This gives me Mola, which is my username.

MsgBox("","","User: " & @UserName & @CRLF & "Computer: " & @ComputerName)

But in the image below, the user's name is "Windows7".

On my pc it shows "Lastname, Firstname" (With my name ofcouce).

And i was just wondering if there was a way to get that name from somewhere?

So my script could say "Welcome, Firstname" instead of "Welcome, user"

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

##### Share on other sites

Or what does this report?

; Generated by AutoIt Scriptomatic May 09, 2012

\$wbemFlagReturnImmediately = 0x10
\$wbemFlagForwardOnly = 0x20
\$colItems = ""
\$strComputer = "localhost"

\$Output=""
\$Output &= "Computer: " & \$strComputer  & @CRLF
\$Output &= "==========================================" & @CRLF
\$objWMIService = ObjGet("winmgmts:" & \$strComputer & "rootCIMV2")
\$colItems = \$objWMIService.ExecQuery("SELECT * FROM Win32_UserAccount", "WQL", _
\$wbemFlagReturnImmediately + \$wbemFlagForwardOnly)

If IsObj(\$colItems) then
For \$objItem In \$colItems
\$Output &= "AccountType: " & \$objItem.AccountType & @CRLF
\$Output &= "Caption: " & \$objItem.Caption & @CRLF
\$Output &= "Description: " & \$objItem.Description & @CRLF
\$Output &= "Disabled: " & \$objItem.Disabled & @CRLF
\$Output &= "Domain: " & \$objItem.Domain & @CRLF
\$Output &= "FullName: " & \$objItem.FullName & @CRLF
\$Output &= "InstallDate: " & WMIDateStringToDate(\$objItem.InstallDate) & @CRLF
\$Output &= "LocalAccount: " & \$objItem.LocalAccount & @CRLF
\$Output &= "Lockout: " & \$objItem.Lockout & @CRLF
\$Output &= "Name: " & \$objItem.Name & @CRLF
\$Output &= "SID: " & \$objItem.SID & @CRLF
\$Output &= "SIDType: " & \$objItem.SIDType & @CRLF
\$Output &= "Status: " & \$objItem.Status & @CRLF
if Msgbox(1,"WMI Output",\$Output) = 2 then ExitLoop
\$Output=""
Next
Else
Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_UserAccount" )
Endif

Func WMIDateStringToDate(\$dtmDate)

Return (StringMid(\$dtmDate, 5, 2) & "/" & _
StringMid(\$dtmDate, 7, 2) & "/" & StringLeft(\$dtmDate, 4) _
& " " & StringMid(\$dtmDate, 9, 2) & ":" & StringMid(\$dtmDate, 11, 2) & ":" & StringMid(\$dtmDate,13, 2))
EndFunc

##### Share on other sites

What does this return >> _WhoAmI

Mola

Or what does this report?

; Generated by AutoIt Scriptomatic May 09, 2012

\$wbemFlagReturnImmediately = 0x10
\$wbemFlagForwardOnly = 0x20
\$colItems = ""
\$strComputer = "localhost"

\$Output=""
\$Output &= "Computer: " & \$strComputer  & @CRLF
\$Output &= "==========================================" & @CRLF
\$objWMIService = ObjGet("winmgmts:\\" & \$strComputer & "\root\CIMV2")
\$colItems = \$objWMIService.ExecQuery("SELECT * FROM Win32_UserAccount", "WQL", _
\$wbemFlagReturnImmediately + \$wbemFlagForwardOnly)

If IsObj(\$colItems) then
For \$objItem In \$colItems
\$Output &= "AccountType: " & \$objItem.AccountType & @CRLF
\$Output &= "Caption: " & \$objItem.Caption & @CRLF
\$Output &= "Description: " & \$objItem.Description & @CRLF
\$Output &= "Disabled: " & \$objItem.Disabled & @CRLF
\$Output &= "Domain: " & \$objItem.Domain & @CRLF
\$Output &= "FullName: " & \$objItem.FullName & @CRLF
\$Output &= "InstallDate: " & WMIDateStringToDate(\$objItem.InstallDate) & @CRLF
\$Output &= "LocalAccount: " & \$objItem.LocalAccount & @CRLF
\$Output &= "Lockout: " & \$objItem.Lockout & @CRLF
\$Output &= "Name: " & \$objItem.Name & @CRLF
\$Output &= "SID: " & \$objItem.SID & @CRLF
\$Output &= "SIDType: " & \$objItem.SIDType & @CRLF
\$Output &= "Status: " & \$objItem.Status & @CRLF
if Msgbox(1,"WMI Output",\$Output) = 2 then ExitLoop
\$Output=""
Next
Else
Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_UserAccount" )
Endif

Func WMIDateStringToDate(\$dtmDate)

Return (StringMid(\$dtmDate, 5, 2) & "/" & _
StringMid(\$dtmDate, 7, 2) & "/" & StringLeft(\$dtmDate, 4) _
& " " & StringMid(\$dtmDate, 9, 2) & ":" & StringMid(\$dtmDate, 11, 2) & ":" & StringMid(\$dtmDate,13, 2))
EndFunc

Computer: localhost
==========================================
AccountType: 512
Disabled: False
Domain: MAN-MOLA15
FullName:
InstallDate: // ::
LocalAccount: True
Lockout: False
SID: S-1-5-21-3427169424-2513921749-2469644734-500
SIDType: 1
Status: OK

---------------------------
WMI Output
---------------------------
AccountType: 512
Caption: MAN-MOLA15\Gjest
Description: Innebygd konto som gir gjester tilgang til datamaskinen/domenet
Disabled: True
Domain: MAN-MOLA15
FullName:
InstallDate: // ::
LocalAccount: True
Lockout: False
Name: Gjest
SID: S-1-5-21-3427169424-2513921749-2469644734-501
SIDType: 1

---------------------------
OK   Avbryt
---------------------------

Then if i spam click OK it goes through alot of users, most likely teachers, and shows most of the same.

After some clicks alot of them have their full name just like "Lastname, Firstname"

But the ones with Mola had either "Student" or "Guest" as name

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

##### Share on other sites

So this isn't on your own system?

##### Share on other sites

What's returned is determined by how your account is set up on the domain. If your user name is Mola, then they may have set your First Name/Last Name to Student in AD, if you're using AD.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

##### Share on other sites

So this isn't on your own system?

Well, no. Im renting from the school so they can give us word and stuff so we don't have to buy it.

So... No, but i get it after school.

What's returned is determined by how your account is set up on the domain. If your user name is Mola, then they may have set your First Name/Last Name to Student in AD, if you're using AD.

Not sure what AD is reffering to...

Nvm

I thought that my name has to be stored in some variable or file.

And maybe there is a function or script that can get that name :/

Edited by Maffe811

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

##### Share on other sites

Have you tried water's UDF?

The AD UDF ? I took a look at it, but it said someplace that most of the functions use AD_Open or something like that.

But im not in school right now, im home. And it still sais my name in the menu.

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

##### Share on other sites

Well thanks anyways!

Ill just have to search around to see if i can do something clever...

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

##### Share on other sites

Func _GetDisplayName()
Local \$aResult = DllCall("secur32.dll", "BOOL", "GetUserNameExW", "int", 3, "wstr", "", "dword*", 256)
If @error Or Not \$aResult[0] Or Not \$aResult[2] Then Return @UserName
Return \$aResult[2]
EndFunc

MsgBox(0, '', _GetDisplayName())

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

## Create an account

Register a new account