Agita 0 Junior Poster in Training

How do I make it so a script will auto-select a users profile name?

ex...

C:\users\ ME \other\stuff

where "ME" is a wildcard that would work in any profile.

Dani AI

Generated

As asked, use the built-in environment variables in your batch file so the script always targets the signed-in user. %USERPROFILE% expands to the full profile folder for the current account; %USERNAME% gives just the account name. Both are present on Windows NT/2000/XP and later.

@echo off
echo Current user: %USERNAME%
echo Profile path: %USERPROFILE%

rem change to the current user's Desktop and copy a file there
cd /d "%USERPROFILE%\Desktop"
copy "%~dp0example.txt" "%USERPROFILE%\Desktop\"

Notes and troubleshooting: always wrap path variables in double quotes to handle spaces. If the batch runs as a different account (scheduled task, service, or "Run as..."), those variables will reflect that account, not the interactive user. As an alternative you can use %HOMEDRIVE%%HOMEPATH% if you need drive+path form. To debug, add echo lines or set at the top of the script to see what values are populated.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.