What are the batch commands/variables. Example [%username% or %groupname%]

Asked

Viewed 1,004 times

-5

How to get more information about variables of this same type/model?

Is there any publication (link) with more information related to these variables?

I need to get as much information from the machine as possible.

4 answers

3

As @Maniero commented, in principle your batch can define the variables you want.

However, what you seem to want to know is how to see the variables currently defined, and this is possible.

Initiate a cmd and execute the following command:

set

All variables previously defined for your user will be shown.

If you run

set <string>

All variables initiated by <string>. For example,

set c

Show all variables started by "c".

  • Thanks, bro, you really helped out.

3

It is not possible, because in the same way that in a code anyone can create variable, then even more so, then there are unlimited variables depending on what you are using. The batch is just an algorithm, it has no predefined variables, they exist in your script or according to the software you are using there. The existing variables depend on the context where you are.

Otherwise it is not in our scope to provide lists of things, just learning concepts and solutions to specific problems, even because lists are mutable.

You can use the command set to list all the variables that are currently available. But not by far is the solution that asks the question. It is a help, but it does not indicate which variables serve what, which gives what the AP wants (and only it knows exactly what it wants), it does not say what is information coming from other applications, which can be misleading, which can be something even reckless that is on your machine fooling something. Don’t consider this a solution.

  • i wanted to know the default variables of windows, but I did not express myself well in the question, vlw;

  • 2

    What Windows? What version? What components are installed on it? What other software might be interfering with it? I don’t think you understand my answer. There’s no way you have an obvious list.

0

Currently there are several commands that can return various information about the computer, the operating system, variables, etc.

In bat, we can use the wmic, systeminfo, reg query among others, as in the example below, a bat taken from this link

@echo off
if %os%==Windows_NT goto WINNT
goto NOCON

:WINNT
echo .Using a Windows NT based system
echo ..%computername%

REM set variables
set system=
set manufacturer=
set model=
set serialnumber=
set osname=
set sp=
setlocal ENABLEDELAYEDEXPANSION
set "volume=C:"
set totalMem=
set availableMem=
set usedMem=
set IPv4=
set Domain=

echo Getting data [Computer: %computername%]...
echo Please Wait....

REM Get Computer Name
FOR /F "tokens=2 delims='='" %%A in ('wmic OS Get csname /value') do SET system=%%A

REM Get Computer Manufacturer
FOR /F "tokens=2 delims='='" %%A in ('wmic ComputerSystem Get Manufacturer /value') do SET manufacturer=%%A

REM Get Computer Model
FOR /F "tokens=2 delims='='" %%A in ('wmic ComputerSystem Get Model /value') do SET model=%%A

REM Get Computer Serial Number
FOR /F "tokens=2 delims='='" %%A in ('wmic Bios Get SerialNumber /value') do SET serialnumber=%%A

REM Get Computer OS
FOR /F "tokens=2 delims='='" %%A in ('wmic os get Name /value') do SET osname=%%A
FOR /F "tokens=1 delims='|'" %%A in ("%osname%") do SET osname=%%A

REM Get Computer OS SP
FOR /F "tokens=2 delims='='" %%A in ('wmic os get ServicePackMajorVersion /value') do SET sp=%%A

REM Get Memory
FOR /F "tokens=4" %%a in ('systeminfo ^| findstr /i "Mem.ria"') do if defined totalMem (set availableMem=%%a) else (set totalMem=%%a)
set totalMem=%totalMem:,=%
set availableMem=%availableMem:,=%
set /a usedMem=totalMem-availableMem

FOR /f "tokens=1* delims=:" %%i IN ('fsutil volume diskfree %volume%') DO (
    SET "diskfree=!disktotal!"
    SET "disktotal=!diskavail!"
    SET "diskavail=%%j"
)
FOR /f "tokens=1,2" %%i IN ("%disktotal% %diskavail%") DO SET "disktotal=%%i"& SET "diskavail=%%j"

( 
>nul echo/%processor_architecture% | findstr /l "...64" && set "processor_architecture_plataform=AMD64"
) || (
set "processor_architecture_plataform=%processor_architecture%
)

echo done!

echo --------------------------------------------
echo System Name: %system%
echo Manufacturer: %manufacturer%
echo Model: %model%
echo Serial Number: %serialnumber%
echo Operating System: %osname%
echo C:\ Total: %disktotal:~0,-9% GB
echo C:\ Avail: %diskavail:~0,-9% GB
echo Total Memory: %totalMem%
echo Used  Memory: %usedMem%
echo Computer Processor: %processor_architecture_plataform% 
echo Service Pack: %sp%
echo --------------------------------------------

REM Generate file
SET file="%~dp0%computername%.txt"
echo -------------------------------------------- >> %file%
echo Details For: %system% >> %file%
echo Manufacturer: %manufacturer% >> %file%
echo Model: %model% >> %file%
echo Serial Number: %serialnumber% >> %file%
echo Operating System: %osname% >> %file%
echo C:\ Total: %disktotal:~0,-9% GB >> %file%
echo C:\ Avail: %diskavail:~0,-9% GB >> %file%
echo Total Memory: %totalMem% >> %file%
echo Used  Memory: %usedMem% >> %file%
echo Computer Processor: %processor_architecture% >> %file%
echo Service Pack: %sp% >> %file%
echo -------------------------------------------- >> %file%

echo %system%, %model%, %serialnumber%, %osname%, > hardware-audit.csv
REM systeminfo | findstr /c:"Host Name" /c:"OS Name" /c:"OS Version" /c:"System Manufacturer" /c:"System Model" /c:"System type" /c:"Total Physical Memory" /c:"Domain"

REM request user to push any key to continue
pause

goto END

:NOCON
echo Error...Invalid Operating System...
echo Error...No actions were made...
goto END

:END

-1


In Windows the command SET already returns the environment variables.

Here returned me:

ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\Laércio\AppData\Roaming
CommonProgramFiles=C:\Program Files\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
CommonProgramW6432=C:\Program Files\Common Files
COMPUTERNAME=DESKTOP-TVVJ9U4
ComSpec=C:\Windows\system32\cmd.exe
DriverData=C:\Windows\System32\Drivers\DriverData
FPS_BROWSER_APP_PROFILE_STRING=Internet Explorer
FPS_BROWSER_USER_PROFILE_STRING=Default
HOMEDRIVE=C:
HOMEPATH=\Users\Laércio
JD2_HOME=D:\JDownloader
LOCALAPPDATA=C:\Users\Laércio\AppData\Local
LOGONSERVER=\\DESKTOP-TVVJ9U4
MOZ_PLUGIN_PATH=C:\Program Files (x86)\Foxit Software\Foxit Reader\plugins\
NUMBER_OF_PROCESSORS=4
OneDrive=C:\Users\Laércio\OneDrive
OS=Windows_NT
Path=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\xampp\php;C:\ProgramData\ComposerSetup\bin;C:\Program Files\Sublime Text 3\;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;C:\Users\Laércio\AppData\Local\Microsoft\WindowsApps;C:\Users\Laércio\AppData\Roaming\Composer\vendor\bin;C:\Users\Laércio\AppData\Roaming\npm
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE=AMD64
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 61 Stepping 4, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=3d04
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
ProgramFiles(x86)=C:\Program Files (x86)
ProgramW6432=C:\Program Files
PROMPT=$P$G
PSModulePath=C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules
PUBLIC=C:\Users\Public
SESSIONNAME=Console
SynaProgDir=Synaptics\SynTP
SystemDrive=C:
SystemRoot=C:\Windows
TEMP=C:\Users\LARCIO~1\AppData\Local\Temp
TMP=C:\Users\LARCIO~1\AppData\Local\Temp
USERDOMAIN=DESKTOP-TVVJ9U4
USERDOMAIN_ROAMINGPROFILE=DESKTOP-TVVJ9U4
USERNAME=Laércio
USERPROFILE=C:\Users\Laércio
windir=C:\Windows
  • 1

    was that, obg <3

  • You can accept the answer as shown in the image: https://i.stack.Imgur.com/eyLkG.jpg

Browser other questions tagged

You are not signed in. Login or sign up in order to post.