English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

On my PC its Owner (C:\Documents and Settings\Owner)
but its not that on every PC, so i want a command that will take it to the user thats logged in - current user

2007-03-29 19:35:21 · 3 answers · asked by Anonymous in Computers & Internet Programming & Design

3 answers

Windows makes this real easy for you.

By default, Windows populates the "username" environment variable with the name of the currently logged on user. Check on your PC. Go to a command prompt and type "set" then hit enter. This will list out your current environment variables. Near the bottom is "username"

You can include this in a batch file by bracketing the variable with %'s. Like,

%username%

You can test that by including a simple line in a batch or from the command line using,

@echo %username%

If you actually want the whole path to the logged on user's profile like "c:\documents and settings\myusername", then just use the builtin %userprofile% environment variable.

@echo %userprofile%

2007-03-31 00:13:55 · answer #1 · answered by Kevin 7 · 3 0

@echo off
for /f "tokens=3 delims=\" %%i in ("%USERPROFILE%") do (set user=%%i) 2>&1
echo "%user%"
pause

This should throw it into a local variable user and then display it on the screen.

2007-03-29 19:46:48 · answer #2 · answered by Plurbis 2 · 0 0

@echo off for /f "tokens=3 delims=" %%i in ("%USERPROFILE%") do (set individual=%%i) 2>&a million echo "%individual%" pause this can prefer to throw it suitable into an area variable individual and then reveal it on the reveal.

2016-12-03 00:28:54 · answer #3 · answered by aoay 4 · 0 0

fedest.com, questions and answers