user name
Moderator: DosItHelp
Re: user name
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
Steffen
Re: user name
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
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
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
Steffen
Re: user name
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?
set C:\users\%username%\desktop an so on?
Last edited by macoga on 03 Oct 2021 14:52, edited 1 time in total.
Re: user name
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
Again:
- open a cmd window
- type SET
- hit the Enter key
- see what variables are predefined
Steffen
Re: user name
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?
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
Code: Select all
if "%drive%"=="1" (set "drive=%userprofile%\desktop")
Steffen
Re: user name
%userprofile%\Desktop will automaticly expand to the user thats logged ins desktop folder
Edit: @agerman: i didnt see your post when i posted mine
Edit: @agerman: i didnt see your post when i posted mine
Re: user name
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
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
As a quick tip, this will get you a list of volume drive letters on their size in bytes on a given system:
You can find other posts on this forum about converting from bytes to gigabytes.
Code: Select all
wmic logicaldisk get name, size
Re: user name
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)
Steffen
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
Re: user name
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?
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?
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: user name
It's just %USERPROFILE%, not C:\Users\%USERPROFILE%. The %USERPROFILE% variable already includes the C:\Users bit.macoga wrote: ↑10 Oct 2021 20:35Hello 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
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.