Page 1 of 2

user name

Posted: 03 Oct 2021 09:39
by macoga
Hello community, I need a command to know the user name of each computer I check, please!!!!

Re: user name

Posted: 03 Oct 2021 12:56
by aGerman
A computer doesn't have a user name. A user might be logged in on a computer. How do you "check" a computer? Remotely (if so, how)? Sitting in front of it?

Steffen

Re: user name

Posted: 03 Oct 2021 13:47
by macoga
Hello agerman, maybe I didn´t explain well.

to make a script that list how many files I have in all the folders in my desktop, I need a first line:

"drive=C:\Users\Anonimo\desktop"

Anonimo is the users name is this case, but if I check another computer I need to change the user name, that is why I thought of a script to do it automatically.

thanks

Re: user name

Posted: 03 Oct 2021 13:57
by aGerman
What about the predefined %userprofile% variable? So, "%userprofile%\desktop" expands to the desktop path of the currently logged-in user. There are a couple more predefined variables (like %username%, to answer your initial question). Run SET in a command prompt to see all of them.

Steffen

Re: user name

Posted: 03 Oct 2021 14:33
by macoga
Sorry Steffen, so the first line of the scrip to ask for the username or userprofile will be?

set C:\users\%username%\desktop an so on?

Re: user name

Posted: 03 Oct 2021 14:43
by aGerman
Why do you want to ask for the user name? I've been talking about pre-defined variables. They already have the right values.
Again:
- open a cmd window
- type SET
- hit the Enter key
- see what variables are predefined

Steffen

Re: user name

Posted: 03 Oct 2021 15:05
by macoga
say if I have a program or a script in a pendrive that takes me to the desktop of the computer I am checking, then at the desktop I want to do copy, move or list, right?

if "%drive%"=="1" (set "drive=C:\Users\Anonimo\desktop"

Then when I want to do another computer there will be a diferent owner or user, so the program should ask first who is the user and change the line above.

that clear the doubt?

Re: user name

Posted: 03 Oct 2021 15:10
by aGerman

Code: Select all

if "%drive%"=="1" (set "drive=%userprofile%\desktop")
%userprofile% expands to C:\Users\Anonimo if you're logged in on your PC, and to C:\Users\Steffen if I'm logged in on my PC. It's really that simple.

Steffen

Re: user name

Posted: 03 Oct 2021 15:15
by AR Coding
%userprofile%\Desktop will automaticly expand to the user thats logged ins desktop folder

Edit: @agerman: i didnt see your post when i posted mine

Re: user name

Posted: 04 Oct 2021 09:18
by macoga
Thanks for the help, there is always a first time of doing this kind of script, that I think they are very usefull if we know how to do them. Now that you indicated the username, my inicial idea was to somehow collect the gigas used in all the folders in each partition in a quick way, not selecting the folders and look at the properties, then change to a diferent partition to do the same, you understand? then the information should be listed in a txt form.

Here is a beginning, you will see my ignorance

Code:
@echo off
color 0A
CLS
:MENU
ECHO.
ECHO Desktop C: - 1
ECHO D: - 2
ECHO E: - 3
ECHO F: - 4
ECHO G: - 5
ECHO H: - 6
ECHO I: - 7
ECHO SALIR - 8
ECHO.
set drive=
set /p drive= HOW MANY GIGABYTES ARE IN EACH PARTITION?
ECHO.
if "%drive%"=="1" (set "drive=%userprofile%\desktop")
)else if "%drive%"=="2" (set "drive=D:"
)else if "%drive%"=="3" (set "drive=E:"
)else if "%drive%"=="4" (set "drive=F:"
)else if "%drive%"=="5" (set "drive=G:"
)else if "%drive%"=="6" (set "drive=H:"
)else if "%drive%"=="7" (set "drive=I:"
)else if "%drive%"=="8" (goto :eof
) else goto :menu


md %drive%\GIGA
if not exist %drive%\GIGA md %drive%\GIGA
for %%x in %drive% do LIST GIGA.TXT >nul 2>nul /-y %drive%\*.%%x %drive%\GIGA

Re: user name

Posted: 04 Oct 2021 10:30
by atfon
As a quick tip, this will get you a list of volume drive letters on their size in bytes on a given system:

Code: Select all

wmic logicaldisk get name, size
You can find other posts on this forum about converting from bytes to gigabytes.

Re: user name

Posted: 04 Oct 2021 10:41
by aGerman
Working with sizes >=2 GB is much more complicated than you may think.
Drives:
viewtopic.php?p=60676#p60676

Folders:
(to calculate the returned bytes into GB you have to use the same :B2Gib subroutine like in the linked post)

Code: Select all

@echo off &setlocal
set "folder=%userprofile%\Desktop"
for /f "tokens=1,2 delims=: " %%a in ('robocopy "%folder%" "%folder%" /L /S /NJH /BYTES /FP /NC /NDL /NFL /TS /XJ /R:0 /W:0') do if /i "%%a"=="Bytes" set "size=%%b"
echo %size% bytes
pause
Steffen

Re: user name

Posted: 10 Oct 2021 20:35
by macoga
Hello there to Steffen, AR Coding and Atfon:
You know the line that you guys suggested

if "%drive%"=="1" (set "drive=C:\Users\%userprofile%\desktop")

Worked for my computer, And I am running windows10, but I got to check another computer with windows 7, and the program didn´t do a thing, investigating what was the user, it showed me in Spanish:

C:\Usuarios\usuario\escritorio
which mean: C:\users\user\desktop

So I changed the line to: C:\Users\user\desktop" but did a folder in C:\users\user\desktop NOT on the desktop and did not list the gigas used by the folders on the desktop.

Would there be a command that will take the user name doesn´t matter where it is, and do the calculation and put it on a list?

Re: user name

Posted: 10 Oct 2021 20:59
by ShadowThief
macoga wrote:
10 Oct 2021 20:35
Hello there to Steffen, AR Coding and Atfon:
You know the line that you guys suggested

if "%drive%"=="1" (set "drive=C:\Users\%userprofile%\desktop")

Worked for my computer, And I am running windows10, but I got to check another computer with windows 7, and the program didn´t do a thing, investigating what was the user, it showed me in Spanish:

C:\Usuarios\usuario\escritorio
which mean: C:\users\user\desktop

So I changed the line to: C:\Users\user\desktop" but did a folder in C:\users\user\desktop NOT on the desktop and did not list the gigas used by the folders on the desktop.

Would there be a command that will take the user name doesn´t matter where it is, and do the calculation and put it on a list?
It's just %USERPROFILE%, not C:\Users\%USERPROFILE%. The %USERPROFILE% variable already includes the C:\Users bit.

Re: user name

Posted: 10 Oct 2021 22:31
by Squashman
How many times do we need to tell you to open up a command prompt and type SET. This will help you understand what all those predefined system variables are.