ACT NOW: The Alteryx team will be retiring support for Community account recovery and Community email-change requests Early 2026. Make sure to check your account preferences in my.alteryx.com to make sure you have filled out your security questions. Learn more here
Start Free Trial

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

GetEnvironmentVariable("USERNAME") No Longer Working

jrlindem
12 - Quasar

Hey all,

 

Started running into this issue after the Windows 10 to 11 change (at least that's what I think is the culprit).

 

My: "GetEnvironmentVariable("USERNAME")" is no longer returning the workflow user's system sign-in ID like it used to.  Has anyone else experienced this and knows of how to resolve it?  This is on Designer Desktop, not Gallery (server).

 

Thanks in advance, -Jay

4 REPLIES 4
binu_acs
21 - Polaris

@jrlindem this env variable working for me in windows 11, can you check the system Environment Variables and check this variable present or not 

 

 

Lajpat_Kurdiya
5 - Atom

Hi, I am completely new to this community. But following Powershell command get help to get the username.

 

PowerShell Methods to Get Username:

# Option 1: PowerShell environment variable
$env:USERNAME

# Option 2: .NET Environment class
[System.Environment]::UserName

# Option 3: Get current Windows identity
[System.Security.Principal.WindowsIdentity]::GetCurrent().Name

# Option 4: WMI query
(Get-WmiObject -Class Win32_ComputerSystem).UserName

For User Profile Path:

# Instead of GetEnvironmentVariable("USERPROFILE")
$env:USERPROFILE

# Or
[System.Environment]::GetFolderPath('UserProfile')

jrlindem
12 - Quasar

Okay, well... after some exhaustive google / copilot searching, I'm not sure that I've got any better explanation for why the GetEnvironmentVariable("USERNAME") isn't working.  Could be associated with my Alteryx Version...

But for anyone who happens upon this thread and needs an alternative solution, you can try using this in a Formula Tool instead:

ReadRegistryString('HKEY_CURRENT_USER\\Volatile Environment', 'USERNAME')

 


Going to close this thread but will happily welcome any other thoughts or ideas.  -Jay

jrlindem
12 - Quasar

@binu_acs 

Didn't see you had replied when I posted my workaround.

I checked the Environment Variables and there wasn't one for "me" but there was for "System Variables".  I attempted to add a new one for "me" as "USERNAME" but I might need to restart my machine before it can be called for.  There was one in the System Variables, but it doesn't seem to be doing anything...


@Lajpat_Kurdiya I had come across those solutions too in my researching.  Thank you for providing them.  I'm trying to avoid that level of workaround so the solution is more stable for the workflow and readability for others when they might want to leverage the same.

Labels
Top Solution Authors