chore(style): add shebang, set bash strict mode, create function
[webi-installers/.git] / sudo / README.md
1 ---
2 title: Sudo for Windows
3 homepage: https://stackoverflow.com/a/40321310/151312
4 tagline: |
5   Sudo for Windows gives you a minimal `sudo` that works in cmd.exe and PowerShell.
6 ---
7
8 ## Cheat Sheet
9
10 > Sudo for Windows isn't real `sudo`, but it's close enough for certain tasks -
11 > like installing WSL (the Windows Subsystem for Linux), without opening a GUI
12 > to Alt-Click "Run as Administrator".
13
14 ### Example: Enabling WSL
15
16 ```bash
17 sudo.cmd dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
18 ```
19
20 ### Raw PowerShell
21
22 `sudo.cmd` is simply an alias of a powershell elevation command:
23
24 ```pwsh
25 @echo off
26 powershell -Command "Start-Process cmd -Verb RunAs -ArgumentList '/c cd /d %CD% && %*'"
27 @echo on
28 ```
29
30 Note: replace `/c` with `/k` if you'd like the window to stay open rather than
31 closing automatically.
32
33 Source: <https://stackoverflow.com/a/55643173/151312>