Table of Contents

Windows CMD windows

basic operation

determine the file itself

@echo Full path and filename: %~f0
@echo Drive: %~d0
@echo Path: %~p0
@echo Drive and path: %~dp0
@echo Filename without extension: %~n0
@echo Filename with    extension: %~nx0
@echo Extension: %~x0
@echo Filename as given on command line: %0
@echo Filename as given on command line minus quotes: %~0
@REM Build from parts
@SETLOCAL
@SET drv=%~d0
@SET pth=%~p0
@SET fpath=%~dp0
@SET fname=%~n0
@SET ext=%~x0
@echo Simply Constructed name: %fpath%%fname%%ext%
@echo Fully  Constructed name: %drv%%pth%%fname%%ext%
@ENDLOCAL
pause

add other exe like python into path of cmd

call python file with same name

@echo off
call python %~dp0%~n0.py
pause

call custom python to run python file with passing parameter (Basic version)

SameNameAsPyFile.bat
set CustPython=D:\Pipeline\App_Win\Python27x64\
%CustPython%python.exe %~dp0%~n0.py %1
pause
SameNameAsPyFile.py
import os,sys
input_count = len(sys.argv)
print('Inputs Count: {0}'.format(input_count))
if input_count>1:
    print('Passing File Path: {0}'.format(sys.argv[1]))

call custom python to run python file with passing parameter (Advanced version)

SameNameAsPyFileAdvanced.bat
:: dont type out cmds in cmd window
@echo off
set CustPython=R:\Pipeline\App_Win\Python27x64\

:: Check for Python Installation
python --version 2>NUL
if errorlevel 1 goto NoPython

::====== hasPython ======
call python.exe %~dp0%~n0.py %1 && goto done
goto console

::====== noPython ======
:NoPython
IF EXIST %CustPython% (
  echo %CustPython%
  call %CustPython%python.exe %~dp0%~n0.py %1 && goto done
  goto console
) ELSE (
  echo Error^: Python not detected  
)
 
:console
pause
:done
SameNameAsPyFileAdvanced.py
import os,sys
input_count = len(sys.argv)
print('Inputs Count: {0}'.format(input_count))
if input_count>1:
    print('Passing File Path: {0}'.format(sys.argv[1]))
    sys.exit(0) # 0: success, 1-127: bad error
else:
    print('Error: No File Passing to Python')
    sys.exit(1)

copy file and directory

copy d:\file1.txt g:\dir1\file1.txt
xcopy d:\download g:\dn /s /e

REM "copy without asking, replace by default
copy /y d:\file1.txt g:\dir1\file1.txt

edit file and directory attribute

attrib +r +a +s +h secureFile.txt

String and Logic Operation

cmd output direction

start a process

Outlook

system operation

explorer operation

file operation

CMD quick actions

Batch file

Batch for registery edit

Windows specific command

REM "format NTFS drive to FAT32 drive"
format /FS:FAT32 /Q X:

control panels and admin tools

management panel
services.msc services panel
compmgmt.msc computer manager
devmgmt.msc device manager
fonts fonts folder
control control panel
control userpasswords2 user manager
control date/time date and time
control desktop display property
control color appearance theme
control panel control somefile.cpl,<optional arguments>
access.cpl Accessibility controls Keyboard(1), Sound(2), Display(3), Mouse(4), General(5)
appwiz.cpl Add/Remove Programs
desk.cpl Display properties Themes(5), Desktop(0), Screen Saver(1), Appearance (2), Settings(3)
hdwwiz.cpl Add hardware
inetcpl.cpl Configure Internet Explorer and Internet properties General(0), Security(1), Privacy(2), Content(3), Connections(4), Programs(5), Advanced(6)
intl.cpl Regional settings Regional Options(1), Languages(2), Advanced(3)
joy.cpl Game controllers
main.cpl Mouse properties and settings Buttons(0), Pointers(1), Pointer Options(2), Wheel(3), Hardware(4)
main.cpl,@1 Keyboard properties Speed(0), Hardware (1)
mmsys.cpl Sounds and Audio Volume(0), Sounds(1), Audio(2), Voice(3), Hardware(4)
ncpa.cpl Network properties
nusrmgr.cpl User accounts
powercfg.cpl Power configuration Power Schemes, Advanced, Hibernate, UPS (Tabs not indexed)
sysdm.cpl System properties General(0), Computer Name(1), Hardware(2), Advanced(3), System Restore(4), Automatic Updates(5), Remote (6)
telephon.cpl Phone and modem options Dialing Rules(0), Modems(1), Advanced(2)
timedate.cpl Date and time properties Date & Time(0), Time Zone(1), Internet Time (no index)

Windows 3rd party command-line utility

NirCmd

download http://www.nirsoft.net/utils/nircmd.html
set default sound device nircmd.exe setdefaultsounddevice “Speakers_TheNameInPanel”
close folder windows nircmd.exe win close class “CabinetWClass”
close empty cmd windows nircmd.exe win close title “C:\Windows\system32\cmd.exe”
off monitor nircmd.exe monitor off
off computer nircmd.exe exitwin poweroff force
pop dialog nircmd.exe trayballoon “Hello” “This is a test…” “shell32.dll,22” 15000
windows control http://nircmd.nirsoft.net/win.html

MS sysinternal suite

PowerShell