ender_scythe
ender_scythe

Reputation: 508

How do I determine the current user in batch?

I'm making some installation systems, and I want it to find the current user, and go to the user's folder. So for example, if the current user is Joe, then I want it to change the directory to Joe's folder instead of Mary's.

Upvotes: 2

Views: 884

Answers (2)

hinneLinks
hinneLinks

Reputation: 3736

I would say that depends totally on the System you use:

For the Username:

  • Windows: echo %username%
  • Linux: echo "$USER"
  • Java: System.getProperty("user.name")

For the User-Home-Directory:

  • Windows: echo %userprofile%
  • Linux: echo "$HOME"
  • Java: System.getProperty("user.home")

(echo is just the command to print something)

Upvotes: 0

SomethingDark
SomethingDark

Reputation: 14305

The %username% system variable contains the current user name.

You can also use %userprofile% as a substitute for C:\Users\<user>

Upvotes: 1

Related Questions