"sudo su" equivalent in windows
Asked Answered
A

2

1

I've seen multiple questions on this topic and some answers about runas but none of them was sufficient...

I need a Windows command to upgrade privileges of a terminal after it has already been opened with permissions of an average user. ie. To upgrade permissions for the whole terminal session and not just to run one command as administrator! Something just like sudo su in Linux.

If anyone knows any trick to do this that would be much appreciated.

Edit:

Why I need this? I use the terminal in Visual Studio Code; it wouldn't let me run commands that require administrative permissions. It sucks to have to open an external terminal to do this... And currently, the only way I'm aware of to run a terminal in VS code in elevated permissions would be by editing the Code.exe's compatibility settings to run as administrator. But that adds more trouble because now it shows the user account control prompt every time I run an instance of VS Code.

Also creating a special shortcut to run VS Code in administrative mode wouldn't help because I run it from the context menu (Open With Code) so I don't have to manually navigate to the project folder.

Amandy answered 19/7, 2020 at 14:27 Comment(3)
The simple reason why you can't find something equivalent to sudo su for Windows is the fact that there is no 100% equivalent on Windows. It is possible to create a shortcut file (.lnk) with Target being %SystemRoot%\System32\cmd.exe /C "C:\Full Path\BatchFile.cmd" with advanced property Run as administrator checked. That's it. A shortcut key can be configured for this shortcut file to run it from within any application. Option /C can be replaced by option /K.Foote
Ok, not necessarily 100%. I just want a solution to my problem... The problem with the special shortcut approach is that I run VS Code from the context menu "Open with VS Code" so I don't have to navigate to the project directory.Amandy
winsourcecode.blogspot.com/2019/12/… - RunAsAdminConsole.exe eleates a existing console or runs a command leaving the console elevated. The program prompts for credentials.Sextuple
O
1

There is no such an equivalent in Windows.

What you might do is to open your desired process from cmd with:

runas /user:administrator processname.

or open any application with right-click and run as..

Osteoclasis answered 19/7, 2020 at 14:27 Comment(3)
Did you try it? In most (non-server) Windows installations, wmic.exe useraccount get Name,Disabled says that the Administrator account is disabled! Moreover, I doubt that a user would know admin password…Spinner
I have tried it, several times, of course. Well, if the user doesn't know the password, then this question isn't about how to hack the root password, I suppose.Osteoclasis
I am also doubting whether you tried it, and wish I could take back my hasty upvote. If you did, were you able to use your own account's password? And what iteration of Windows? I'm on my laptop which is Windows 11. My account is an admin, And I don't remember ever setting up the Administrator account with its own password.Pinot
B
0

2020: There is no such an equivalent on Windows.

2024: Jordi Adoumie (PM at Microsoft for Windows) announce on Twitter:

I'm excited to OFFICIALLY announce sudo for Windows!
Our team has been working hard on this feature, and you can now test it out in the latest insider canary build. Best part? We're working to open-source the project on GitHub.

You need Windows 11 Insider Preview Build 26052

It refers to:

It includes a mode which addresses the OP ("I need a Windows command to upgrade privileges of a terminal after it has already been opened with permissions of an average user.")

Configuration Option 3: Inline

This configuration is most similar to the behavior of sudo on other operating systems. In this configuration, Sudo for Windows will run the elevated process with its stdin, stdout, and stderr all connected to the current window.
This means the new elevated process can take in input and route output to the current window.

When elevating a process from the command-line with sudo, a UAC dialog will appear asking the user to confirm the elevation.

Barbabas answered 8/2 at 23:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.