Variable 'username' auto-defined in scripts

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
kellianjaxon
Posts: 4
Joined: 20 Dec 2015, 14:19

Variable 'username' auto-defined in scripts

07 Sep 2018, 11:22

Environment:
Windows 7 Enterprise
AHK 1.1.29.1 Unicode 32-bit

Symptom: Execute the command 'msgbox % username' in the first line of a script.
Expected behaviour: Display an empty messagebox.
Actual behaviour: Display a messagebox as if there was a prior assignment 'username := a_username' in the script.
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Variable 'username' auto-defined in new scripts

07 Sep 2018, 11:27

Yeah and this is why you should use

Code: Select all

#NoEnv
on top of your script.

Some background: This is an environment variable that is set for the AutoHotkey process.
If you dont use #NoEnv Autohotkey will get the values of these environment variables instead of no value - like you expected.
Another example is PATH.
Recommends AHK Studio
kellianjaxon
Posts: 4
Joined: 20 Dec 2015, 14:19

Re: Variable 'username' auto-defined in new scripts

10 Sep 2018, 01:44

nnnik wrote:Yeah and this is why you should use

Code: Select all

#NoEnv
on top of your script.

Some background: This is an environment variable that is set for the AutoHotkey process.
If you dont use #NoEnv Autohotkey will get the values of these environment variables instead of no value - like you expected.
Another example is PATH.
Ah, of course. It didn't occur to me 'USERNAME' actually is by default an environment variable, having hardly ever used that one.

Thanks for the clarification! My bad.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], peter_ahk and 164 guests