windows – Store logged in user in .bat variable

Question:

I have to create a bat to automate the installation of the company's standard programs, but one in particular is giving me a headache.

The installer of one of the programs, by default, creates the path C:\app\client\\product\12.1.0\client_1 for installation. However I need to replace a file inside the installation folder after it is installed.

The file replacement would be OK if it wasn't for the username in the path generated by the program's installer. I could even change the path, but the idea is to automate everything, so that the user clicks next > next > next without having to look at what he's doing.

My question is: How do I get the username of the current windows session (10 PRO, if the version makes a difference), and store it in a variable.

I tried to use WMIC COMPUTERSYSTEM GET USERNAME but I can't store it in a variable.

To be honest, I don't know much about bash programming, but it's just that part of the code that's missing and I can't fix it.

Answer:

Use the %username% global variable.

Scroll to Top