Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

When I create a batch file on my computer to execute start c:\Users\________\Whatever\..., it works on my machine.

How can I get it to work on someone else's machine, since their username isn't my username?

share|improve this question

2 Answers 2

You can use the Environmental Variable %USERPROFILE%. This works from Windows XP and on, and automatically detects the drive letter, and the folder path, to the current user's profile folder.

start %USERPROFILE%\Whatever

share|improve this answer

You can use the Windows environment variables. One you could use in this case would be %username%, which returns the current user's name.

ie:

start c:\users\%username%\Whatever

Additionally/alternatively, if you're specifically aiming for the user's profile folder (<drive>:\users\<username>) you can use the %userprofile% variable, which will return the full path to the current user's profile, which helps when targeting older OSs like XP (where it's <drive>:\document and settings\<username> by default), or where the profile folder has been moved to a different drive/location.

ie:

start %userprofile%\Whatever

There's several other variables in there that you may find useful in writing batches, I'd advise perusing the entire list. :)

share|improve this answer
2  
I'd upvote if it wasn't for my last two Windows systems having kept the user profiles in e:\users and d:\documents and settings... –  grawity Jun 4 at 19:10
    
@grawity I tried to keep it generic by showing him the list of available variables, and not assuming they always want to target the user profile directory. But hey point taken, so I updated it to cover the %userprofile% variable as well. –  Ƭᴇcʜιᴇ007 Jun 4 at 19:21
    
Dude, you just stole my answer :P –  Canadian Luke Jun 4 at 19:21
    
Not stolen, just expanded on my answer to make it more full. Again, I tried to avoid making it specifically about the user profile directory originally, but apparently if I don't cover %userprofile% as well, then it's not a 'correct' answer. ;) –  Ƭᴇcʜιᴇ007 Jun 4 at 19:23
    
Don't worry, with the tongue sticking out in the comment, it's meant as a joke :) –  Canadian Luke Jun 4 at 19:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.