Windows OS Hub
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server 2025
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
    • Proxmox
  • PowerShell
  • Linux
  • Home
  • About

Windows OS Hub

  • Windows
    • Windows 11
    • Windows 10
    • Windows Server 2025
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
    • Proxmox
  • PowerShell
  • Linux

 Windows OS Hub / Windows 11 / Run Elevated Commands with Sudo on Windows 11

July 16, 2025

Run Elevated Commands with Sudo on Windows 11

Starting with build 24H2, Windows 11 includes a built-in sudo command. This command allows running commands as an administrator directly from an unprivileged (non-admin) CMD/PowerShell/Terminal session.

By default, the sudo command is disabled in Windows 11. To allow using this tool, use the Enable sudo toggle switch in Settings -> System -> For developers.

Enable sudo on Windows 11

Or you can enable sudo via the Windows registry.

reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Sudo" /v "Enabled" /t REG_DWORD /d 1 /f

For example, running the following PowerShell command to restart a Windows service from a non-elevated terminal will result in an error

Restart-Service iphlpsvc

Then, enable sudo in the Windows settings and run the same command via sudo.

sudo powershell "Restart-Service iphlpsvc"

A User Account Control (UAC) prompt will appear requesting privilege elevation. Once approved, a new terminal window is launched (separate from the current session where context was already established), and the specified command is executed with administrative rights.

sudo - UAC elevation prompt

Running elevated PowerShell command using sudo in Windows 11

Unlike runas, the sudo command doesn’t prompt for an administrator password in the command line. The UAC prompt is used to confirm and elevate the current user’s privileges, but it does not allow selecting a different user account for elevation.

In the same way, you can use Sudo in the CMD prompt. I’m trying to stop the service using a non-admin (non-elevated) command prompt.

net stop iphlpsvc

System error 5 has occurred.
Access is denied.

Now I run the same command via sudo:

sudo net stop iphlpsvc

use sudo command in CMD prompt

Previously, running a program or command with elevated permissions from a non-privileged console required launching a new Command Prompt window using the “Run as administrator” option. If the PowerShell console was running in non-admin mode, you had to start an elevated session from within the current session using this command:

Start-Process powershell -Verb runAs

Sudo for Windows runs apps with elevated privileges in three modes. These modes can be selected from the Settings app or specified from the command line.

  • In a new window – when a command or program is run via sudo, it opens in a new elevated window (session), running as an administrator. This is the default behavior. sudo config --enable forceNewWindow
  • With input disabled – this is the safest option, where the command runs with elevated privileges in the current window but cannot receive or prompt for user input within that session: sudo config --enable disableInput
  • Inline – this mode is most similar to the behavior of the sudo command in Linux and other OSs. An elevated command runs in the current console and can receive input from it (the most convenient but least secure option): sudo config --enable normal

sudo modes in Windows 11

You can run an elevated command in the current console using sudo, regardless of the current sudo mode. Just add the inline option.

sudo --inline net stop iphlpsvc

sudo --inline - elevate command in current session

To see the full list of supported sudo options and parameters in Windows, run the following command:

sudo -h

sudo command line options in Windows

0 comment
1
Facebook Twitter Google + Pinterest
PowerShellQuestions and AnswersWindows 11
previous post
Find a Process Causing High Disk Usage on Windows

Related Reading

Configuring RemoteApps Hosted on Windows 10/11 (without Windows...

January 25, 2025

Disable BitLocker Automatic Drive Encryption in Windows 11

October 16, 2024

Get Started with Docker on Windows (WSL2) without...

September 4, 2024

Enable Hyper-V on Windows 10/11 Pro and Home...

August 12, 2024

Disable and Completely Remove Widgets from Taskbar in...

September 26, 2024

Adding Multiple Alternate DNS Names for a Windows...

September 3, 2024

Fix: Windows Update Tab (Button) is Missing from...

December 16, 2024

Check the Software Installation/Removal History in Windows

October 8, 2024

Leave a Comment Cancel Reply

join us telegram channel https://t.me/woshub
Join WindowsHub Telegram channel to get the latest updates!

Recent Posts

  • Find a Process Causing High Disk Usage on Windows

    July 15, 2025
  • Fix: Microsoft Defender Not Updating Automatically in Windows

    July 8, 2025
  • Create a Windows Server VM on Proxmox (Step-by-Step)

    July 7, 2025
  • How to Detect Which User Installed or Removed a Program on Windows

    June 23, 2025
  • Encrypt Any Client-Server App Traffic on Windows with Stunnel

    June 12, 2025
  • Failed to Open the Group Policy Object on a Computer

    June 2, 2025
  • Remote Desktop Printing with RD Easy Print Redirection

    June 2, 2025
  • Disable the Lock Screen Widgets in Windows 11

    May 26, 2025
  • Configuring Windows Protected Print Mode (WPP)

    May 19, 2025
  • Map a Network Drive over SSH (SSHFS) in Windows

    May 13, 2025

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Run PowerShell Scripts on a Schedule with Task Scheduler
  • How to Assign (Passthrough) a Physical GPU to a Hyper-V Virtual Machine
  • Extend an Expired User Password in Active Directory
  • Check Windows 11 Hardware Readiness with PowerShell Script
  • How to Enable and Configure Wake-on-LAN (WoL) in Windows
  • How to Find Windows Version and Build Number Installed
  • Check the Software Installation/Removal History in Windows
Footer Logo

@2014 - 2024 - Windows OS Hub. All about operating systems for sysadmins


Back To Top