A quick reference to Batch and CMD.
Created on: 2019-08-30
Tag: cheat_sheet
Warning
under heavy construction and not well organized
add %cd%/ before file.name to get current location ie. pwd:
if exist file.name ( echo "file exists" ) else ( echo "file doesn't exist" )
echo %USERNAME%
echo %USERDOMAIN%
run 'set' to see the full list
rmdir /S /Q "path\to\folder" :: /Q for quiet mode /S for sub-folder
call "file.bat"
del /Q "path\to\folder" :: /Q for quiet mode
(New-Object Net.WebClient).DownloadFile('http://www.foo.com/package.zip', 'package.zip')
powershell -Command "powershell_command"
powershell -Command "(New-Object Net.WebClient).DownloadFile('https://download.url', 'path\to\save\with\file.extension')"
takeown /f "DRIVE:\cygwin" /r /d Y
unrar x "%rar_loc%" "%ext_loc%"
shortcut /a:c /f:"path/to/destination.lnk" /t:"path/to/source.extension"
(source:http://stackoverflow.com/a/32105548/5350059)
sfx.exe -y -gm2 -InstallPath="C:\\your\\target\\path" can also extract sfx.7z.exe
Taskkill /IM application_name.exe /F
set loc= \path\to\folder for %%f in (%loc%) do set output=%%~nxf ::output gives the folder name echo %output%
wmic logicaldisk get caption,providername,drivetype,volumename
set script_path=C:\all\ball set script_drive=%CD:~0,3% echo %script_drive%
# note if 2 is used in place of 1 we get C:
chdir /d %drive_letter%:
set cmd="%cmd%" for /f "tokens=*" %%i in (' %cmd% ') do set x=%%i
command>output.txt
for /f "tokens=*" %%a in ('type "my file.txt"') do [process] %%a
set "var=%%a"
shutdown /l /f
WinRAR.exe x -ibck %app_name%.zip %folder_name%
(source: http://stackoverflow.com/a/19337595)
::hide net user hidden /active:no ::unhide net user hidden /active:yes
(source: http://www.wikihow.com/Create-and-Manage-a-Hidden-Account-in-Windows-7)
rundll32.exe user32.dll,LockWorkStation
(source: http://winaero.com/blog/all-ways-to-lock-a-windows-10-pc/)
cd \ dir /s /b mytool.exe ::OR to find firefox on C:\ where /R c:\ firefox.exe
(source: https://superuser.com/a/49107/655587)
set /p texte=< file.txt echo %texte%
command >NUL
xcopy *.* C:\flashdrive1 /a (/a only copies files with the archive bit set, ie. those that have changed.) attrib -a /s (resets the archive bit. It is set when changes are made to a file.)
` <>`_