Using current user profile path in batch file




















Connect and share knowledge within a single location that is structured and easy to search. You can get a complete list of environment variables by running the command set from the command prompt.

Obviously this can be easily spoofed, so don't rely on it for security. Depending on how you are running your batch file, this is not necessarily the same as the name of the current user. For example, you might be running your batch file through a scheduled task, from a service, etc. Here is a more sure way of getting the username of the currently logged on user by scraping the name of the user that started the explorer. In the old cmd.

In the PowerShell command prompt or a. Name - Gives you the fully qualified username e. Since you must include the password in plain text if authentication is required, I will only use it in a completely private environment where other users cannot view it or if a user seeing the password would bear no consequences. Anyway, if you want something foolproof, get Visual Studio Express and compile the following:.

If you want to know the latter, run:. If you just want the username just write. The advantage is that It works with windows 10 windows 8 server As far as I remember with also other OS like Win7 etc. And yeah via batch you can simply use. In a standard context, each connected user holds an explorer. This also runs perfectly under Windows 7. In rare cases explorer. If the command return an empty line then it is likely that no user is logged on.

As far as find BlueBearr response the best while I,m running my batch script with eg. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow.

Learn more. How do you find the current user in a Windows environment? Ask Question. Asked 12 years, 2 months ago. Active 4 months ago. Viewed k times. When running a command-line script, is it possible to get the name of the current user? Add a comment. Active Oldest Votes. Improve this answer. Oded Oded k 96 96 gold badges silver badges bronze badges. Please note that this does not include the drive on which the home directory is located.

What if I have wrong drive active and I don't want to hard code C: for example? Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. Improve this answer. Community Bot 1. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Making Agile work for data science. Stack Gives Back Featured on Meta.

New post summary designs on greatest hits now, everywhere else eventually. Related 1.



0コメント

  • 1000 / 1000