Give administrator privileges to existing powershell

7

1

Having a powershell opened, it's possible to give it administrator priviledges ?

It's embedded in an IDE (Visual Studio Code) and I don't want to open a new terminal everytime I do something that needs administrator priviledges (like npm install ... --save-dev)

If not, can I set VS Code to open terminals with administrator priviledges ?

Alex Huiculescu

Posted 2017-10-03T12:04:54.963

Reputation: 73

2Try opening VS Code as administrator, this may provide admin privileges to the terminal as well, I guess. – Ĭsααc tիε βöss – 2017-10-03T12:09:15.163

No; In order for a process to have escalated permissions it must be started with escalated permissions. This is the reason whenever an application requests elevated permissions the process is relaunched. – Ramhound – 2017-10-03T14:03:04.003

Have you looked in VSC's User Settings? The path to PS is there, along with other PS parameters. Not sure if VSC launched with standard privileges could start a child process as admin, though. – root – 2017-10-03T14:41:19.423

@Ĭsααctիεβöss VSC is started with standard priviledges. If I start it with Admin priviledges, powershell will have admin too. Thank you – Alex Huiculescu – 2017-10-04T10:16:13.487

@root VCS has a bunch of settings for terminal, but not the one to start the powershell as admin. – Alex Huiculescu – 2017-10-04T10:16:18.283

@Ramhound can you give me some more details ? I just started Operating Systems course and I'd like to learn from the docs – Alex Huiculescu – 2017-10-04T10:16:20.617

@Ĭsααctիεβöss You should post this as an answer and the requester should accept this as an answer. – root – 2017-10-19T15:07:08.790

This used to be able to be resolved as mentioned in this writeup, however I wasn't able to replicate using PowerShell 6 (with ConEmu, VS Code, or the new Terminal), however you should be able to do research on google to figure out what needs to be modified in the writeup's Restart-Host function. However, what should never be done is running VS Code with Admin privileges, as it allows arbitrary code from within VS Code to execute with admin privileges on the host << Massive Security Risk

– JW0914 – 2019-08-19T16:20:57.197

Answers

7

Since my suggestion(comment) has worked for the OP, I'm posting this as an answer

Launch the VSCode as an administrator, so that the integrated powershell also gets the admin privileges as you expected.

Instead every time you right-click and "Run as administrator", navigate to the installation folder of the VSCode program, and do as the following demonstration shows. enter image description here

Note: The files you create this way within VSCode are then also owned by the administrator. This probably isn't an issue in most of the cases. But there are scenarios where this, at least, creates a higher effort for you when handling those files.

Ĭsααc tիε βöss

Posted 2017-10-03T12:04:54.963

Reputation: 1 772

4This is a massive security issue and would never be recommended for a myriad of reasons... first and foremost, it allows arbitrary code from with VS Code to execute with admin privileges on the host and is a recipe for disaster. – JW0914 – 2019-08-19T11:54:38.650