Get Username

Hi!

I tried to get the current user’s username with the Get Username activity; however, it seems to only work by getting the email of a specifically programmed user. What logic can I use to actually capture the individual’s Windows/desktop account? I need to capture it and save it to a variable. I tried using Command Prompt with whoami, but the results show null. For example, mine is bterry.CORP, but there could be another person whose user account jsmith. Any advice you can provide is greatly appreciated! Have a wonderful day!

1 Like

Hi! Hope you are well.

If I understood correctly, what you wish to capture is the username of the current Windows session. We can easily capture this value by opening a Command Prompt, and entering the command “whoami”, like so:

In your workflows, this can be done via the “Command Prompt” activity, which can be found in the OS Automation > System category.

You’d simply need to input the “whoami” command, and then you can use an “Assign value to variable” activity next that saves the previous step’s result, and you’ll get the username.

The result will then look like this:

ans3img3

Notice that the \ character is repeated, this is automatic character escaping for JavaScript (which ElectroNeek is built on). And you’ll also notice that at the end of the value, there’s a text that says “\r\n”. This is a line break.

If you wish to remove those line breaks, you can either use the “Extract text” activity, or simply add an “Assign value to variable” activity, and with the “Calculate a value” option use the “.replace” string method.

As an additional note, the “Get Username” activity you were using at first is for a different purpose - extracting the username of a credential saved to the Credential Management section of ElectroNeek. You can check more details in this Help Center article.

Hope this has helped!

@Ivan_Ramos thank you so much, my friend! I’m unsure why it didn’t do it before. Did the variable have to be named username? It’s working with that. Thank you again!

2 Likes

The variable does not need to be named username, no, that was simply an example. The same workflow I shared should work with any variable name, as long as it follows the restrictions for variable names that you can read in this article.

In any case, you’re welcome! I’m glad that it’s working now!

1 Like

Hey @Ivan_Ramos

I just wanted to let you know why I wasn’t getting the result I expected using the Command Prompt whoami command. I had the Execute in Background checkbox clicked. When this is clicked, null is the value saved in the variable. When it isn’t, it works perfectly.

2 Likes