sudo !! equivalent on Windows cmd

13,585

You can try gsudo, a sudo for windows that allows either to run commands with elevated permissions on the current console, to elevate the current shell, or launch elevated commands on a new console.

Examples

gsudo {command} [arguments]
gsudo md "C:\Program Files\MyApp"

# spawn the current shell (Cmd/PowerShell/PSCore) in a new console window
gsudo -n

# spawn PowerShell in a new console window
gsudo -n powershell

UPDATE: Since gsudo v0.7.1, it supports the Unix-sudo Bang Bang syntax, on CMD:

  • gsudo !! elevates the last executed command.
  • gsudo !prefix elevates the last executed command that starts with prefix.
  • gsudo !?infix elevates the last executed command that contains infix.

Installation

  • Install with Scoop: scoop install gsudo
  • Install with Chocolatey: choco install gsudo

Manuall installation methods, docs & source at https://github.com/gerardog/gsudo

Share:
13,585

Related videos on Youtube

Outman
Author by

Outman

Certified C# Programmer and a Microsoft Certified Professional.

Updated on September 18, 2022

Comments

  • Outman
    Outman over 1 year

    I'm looking for a cmd.exe equivalent to Linux's sudo !! and other bang-commands such as !x, !?x, !!:p and !!* mentioned here.

    • phuclv
      phuclv over 5 years
      I don't think so, cmd is an ancient beast with a lot of unfixable problems due to backward compatibility. You don't even have an equivalent to sudo in Windows. Powershell is much more powerful and you can do the above things with Get-History
    • NotepadPlusPlus PRO
      NotepadPlusPlus PRO over 5 years
      You can try cygwin if you really miss Linux commands.
    • Outman
      Outman over 5 years
      @Cricrazy cygwin is great, but my use case exclusively involves cmd.
    • RaSedg
      RaSedg almost 4 years
      The just released gsudo v0.7.1 suports !! on CMD. :)
  • RaSedg
    RaSedg about 4 years
    Unfortunately this doesn't works in Windows 10. It will run as that user but without elevation/admin rights.
  • harrymc
    harrymc about 4 years
    @GerardoGrignoli: You are right that a Linux user will expect this, although Windows is different. I added links to some some self-elevation methods.
  • pooter03
    pooter03 over 2 years
    Brilliant! Especially fun as I used winget to install it for that extra-pseudo 'nux feel. :)