The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,860 other subscribers

gsudo (sudo for windows)

Posted by jpluimers on 2025/09/01

Not that long ago, I bumped into [Wayback/Archive] Home | gsudo (sudo for windows)

I wish I had bumped into this much longer ago (:

Source at [Wayback/Archive] gerardog/gsudo: Sudo for Windows.

One installer package (there are others like winget and scoop on the documentation site): [Wayback/Archive] Chocolatey Software | gsudo – a sudo for windows.

Via [Wayback/Archive] windows – How can I auto-elevate my batch file, so that it requests from UAC administrator rights if required? – Stack Overflow (thanks [Wayback/Archive] Gerardo Grignoli)

Edit 20250901 (thanks [Wayback/Archive] mterwoord (Matthijs ter Woord) · GitHub):

Windows 11 has a built-in sudo which has different semantics, and is disabled by default.

Enabling Windows 11 sudo

C:\bin> sudo
Sudo is disabled on this machine. To enable it, go to the Developer Settings page in the Settings app

What it fails to show is that you can start it from the command-line using this:

start ms-settings:developers

The other way to enable is by running this command as elevated user on the command line:

sudo config --enable normal

A tricky thing is that command line help is spread over two commands without telling you so.

Windows 11 sudo command line help

There is sudo /? which gives about half the help only for the sudo run command:

C:\bin> sudo /?
Run a command as admin

Usage: run [OPTIONS] [COMMANDLINE]...

Arguments:
  [COMMANDLINE]...
          Command-line to run

Options:
  -E, --preserve-env
          Pass the current environment variables to the command

  -N, --new-window
          Use a new window for the command

      --disable-input
          Run in the current terminal, with input to the target application disabled

      --inline
          Run in the current terminal

  -D, --chdir 
          Change the working directory before running the command

  -h, --help
          Print help

And there is the sudo -h help itself showing the run, config and help options (the help one shows the previous sudo /? information):

C:\bin> sudo -h
Sudo for Windows

Usage: sudo [OPTIONS] [COMMANDLINE]... [COMMAND]

Commands:
  run     Run a command as admin
  config  Get current configuration information of sudo
  help    Print this message or the help of the given subcommand(s)

Arguments:
  [COMMANDLINE]...  Command-line to run

Options:
  -E, --preserve-env   Pass the current environment variables to the command
  -N, --new-window     Use a new window for the command
      --disable-input  Run in the current terminal, with input to the target application disabled
      --inline         Run in the current terminal
  -D, --chdir   Change the working directory before running the command
  -h, --help           Print help (see more with '--help')
  -V, --version        Print version

It also reveals there are three more help commands:

The not so useful sudo help help:

C:\bin> sudo help help
Print this message or the help of the given subcommand(s)

Usage: sudo help [COMMAND]...

Arguments:
  [COMMAND]...  Print help for the subcommand(s)

The more useful sudo help config:

C:\bin> sudo help config
Get current configuration information of sudo

Usage: sudo config [OPTIONS]

Options:
      --enable   [possible values: disable, enable, forceNewWindow, disableInput, normal, default]

And the previously mentioned sudo help run:

C:\bin> sudo help run
Run a command as admin

Usage: sudo run [OPTIONS] [COMMANDLINE]...

Arguments:
  [COMMANDLINE]...  Command-line to run

Options:
  -E, --preserve-env   Pass the current environment variables to the command
  -N, --new-window     Use a new window for the command
      --disable-input  Run in the current terminal, with input to the target application disabled
      --inline         Run in the current terminal
  -D, --chdir   Change the working directory before running the command

References

The second one shows that in the past, enabling did not always succeed.

Queries

In retrospect, the first query had the “Pureinfotech” page (almost) at the top of the results. The second query will lead to a blog post later this year.

--jeroen


Image from the gsudo documentation:

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.