Windows users who are familiar with Linux or other Unix-like operating systems may have wished for a way to run elevated commands from an unelevated console session, without having to open a new elevated console or use the runas command. Now, with the latest Windows 11 Insider Preview Build 26052, they can do just that with a new feature called Sudo for Windows.
Sudo for Windows allows users to run elevated commands directly from an unelevated console session, such as PowerShell or Command Prompt. It is inspired by the sudo command on Linux and other Unix-like operating systems, which stands for “superuser do” and lets users execute commands as another user, usually the administrator or root.
To use Sudo for Windows, users need to enable it in the Windows Settings app, on the “Developer Features” page. They can also choose from three different configuration options for how Sudo for Windows will run the elevated process:
- In a new window: This option will open a new elevated console window and run the command in that window. This is the default option when sudo is enabled.
- Input closed: This option will run the elevated process in the current window, but with its stdin closed. This means that the process will not accept any user input, so this option will not work for processes that require further user input after elevation.
- Inline: This option will run the elevated process with its stdin, stdout, and stderr all connected to the current window. This means the process can take in input and route output to the current window. This option is most similar to the behavior of sudo on Linux and other operating systems.
To run a command with Sudo for Windows, users simply need to type sudo followed by the command they want to elevate. For example, to run netstat -ab, which displays the active TCP connections and the executable involved in creating each connection, users can type:
sudo netstat -ab
A User Account Control (UAC) dialog will appear, asking the user to confirm the elevation. Once the user confirms, the command will be executed with the selected configuration option.
Sudo for Windows is a new and convenient way for users to run elevated commands from unelevated consoles, without having to switch between different windows or use the runas command. It is also a familiar and ergonomic solution for users who are used to the sudo command on other operating systems. Sudo for Windows is still in development, and Microsoft welcomes feedback and suggestions from users on its GitHub repository.
Leave a Reply