I'm looking for a way to be able to open cmd as admin with code. So like linux. We just execute "sudo su" command for be admin. But ı want this for windows. So ı want execute a command in cmd like "sudo su" and be admin. How can ı do this?
3 Answers
runas /savecred /user:myadminaccount "myprocess.exe"

- 8,409
- 22
- 75
- 99

- 11
- 1
-
3While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value. – Donald Duck Dec 05 '20 at 10:13
-
Add a LocalUser and make them admin... For example, sudo. Then replace myadminaccount with 'sudo'. – DrBB Jul 21 '22 at 18:27
if ypu mean open an administrative commandline you havd a few options:
1: Right click run as adminiatrator on the cmd shortcut or executable
2: Right click, open properties of shortcut or exe, click "run with administrator priviledges" and click okay, now when you open it it launches as administrator
3: launch cmd from a powershell session specifying to run cmd as administrator
4: from wirhin cmd, run powershell directly, with the appropriate switches to run it as administrator.
-- Not at my computer and dont remember the powershell commands needed to do this offhand.
So I will fill that in later if this is the needed solution, or anothwr member may do so ofc. either by editing this or answering seperately.
just let us know if that was the real need you wanted.

- 3,074
- 1
- 22
- 29