Question : How do I find the logged in Username from a batch file?

I am setting up a workstation backup script that utilizes Robocopy and is run from a Scheduled Task using a Service Account.  I want it to copy certain files from C:\Documents and Settings\Username\My Documents from the logged in user.  So I'm using the command:

robocopy "%USERPROFILE%\My Documents"

But %USERPROFILE% is being resolved as the Service Account instead of the logged in user.  Is there any way I get the logged in user info when running a batch file as another user?

Answer : How do I find the logged in Username from a batch file?

make sure you have a space after \ in the delims...it's backslash "\" AND space " "
Random Solutions  
 
programming4us programming4us