Windows CLI
From wikinotes
The windows commandline is undergoing a transition from cmd.exe (batch) to the newer powershell.
File Management
explorer . # open file explorer
dir # print contents of dir
cd /d C: # change drive letter
cd C:\dir # change directory
md C:\dir # make directory
del /Q C:\file.ext # delete a file
move C:\file.ext C:\other\file.ext # move file
xcopy C:\dir C:\dest /E/H/R/Y/J # copy dir and subdirs
mklink /j C:\dst C:\src # create symlink
msg /server:wintermute will "message to display" # display message over network
icalcls myfile.txt /grant Owner:F Group:R Everyone:R # change file permissions
icalcls myfile.txt /setowner "willjp" # change file owner
Process Management
tasklist # display all running processes
taskkill /IM notepad.exe # kill process notepad
Exit Codes
A list of windows installer exit codes: https://docs.microsoft.com/en-us/windows/win32/msi/error-codes
Notably, installers can exit 0
(success) and 3010
(success, needs reboot).
Mounting
list vol # list all disks known to windows
net use K: \\groot\movies /USER:smbguest MyPassword # temporarily mount \\groot\movies to K:
net use K: \\groot\movies /USER:smbguest MyPassword /P:Yes # permanently mount \\groot\movies to K:
net use K: /delete /y # unmount K: (if mount created using net use)
subst P: C:\test # mount dir as drive-letter
fsutil fsinfo drives # show info about detected drives
Registry
reg query "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" /v AllowRemoteRPC # Query Registry Key
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" /v AllowRemoteRPC /t REG_DWORD /d 1 /f # Create/Modify registry key
File Associations
REM associate a file extension with a type
assoc .c=sourcecode
assoc .py=sourcecode
REM associate a type with a program (%l means file)
ftype sourcecode="C:\myprog.exe" -abc --some-flag "%l"
Windows Features
REM list features
dism.exe /online /get-features
REM enable a feature
dism.exe /oneline /enable-feature /FeatureName:Microsoft-Windows-Subsystem-Linux
Hardware Information
wmic cpu # cpu info
wmic memcache get access # swap info
typeperf "\Processor(_Total)\% Processor Time" # overall cpu info
typeperf "\Processor{*)\% Processor Time" # indv. cpu info
typeperf "\memory\available bytes" # total ram
typeperf "\memory\committed bytes" # used ram
systeminfo # print system info
Environment Variables
REM Persistent EnvVars are set in registry
reg add "HKCU\Environment" /v MY_ENVIRONMENT_VAR /t REG_EXPAND_SZ /d "Hello World!" /f
REM Local EnvVars
set VAR="blah"
AutoRun
REM you can set autorun scripts in the registry
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
Users, HomeDirs
%HOMEDRIVE%%HOMEDIR%\ # current user's homedir
C:/Windows/System32/config/systemprofile/ # service user 'Local System's homedir (for ssh, etc)
Gnu-CoreUtils
You can install the gnu-coreutils on windows (gfind, gawk, gls, ...etc). They do run a little slower,
but can be useful to have on hand. I seldom install these now, I'll just use git-bash
.
Console
Windows cmd-prompt has improved a lot (resizable, colors, ..). You can use other programs to make it a little more similar to unix if you'd like.
cmder |
conemu |
clink |