58 points · by barlog · 9y ago · 70 comments
Or if you know the admin account you could use something like
Invoke-Command -ScriptBlock { ls } -ComputerName $env:COMPUTERNAME -Credential (Get-Credential)Not if I want resemblance with Bash-like shells. I guess that's also the point of this: Most people already know sudo from Linux and cmd.exe, now they can use both together.
(Plus powershells structured output so you can use 'where' and 'select' and 'get-member' rather than scraping with regexs. )
Emblematic of what's wrong with the Powershell (or perhaps MS as a whole) philosophy: you don't build this functionality into a shell, you build a file system module (you'd do it with FUSE if on Linux) that "mounts" the registry as a bunch of files. Then you could edit it in any shell or text editor, or even in a GUI file manager and GUI text editor if you wanted to.
It isn't that hard to build a decent shell, if zsh can do it, why can't MS put a few decent interns on it and get their act together? I feel like I'm knocking skulls together whenever I end up talking Powershell with someone from across the lake here in Seattle, this stuff isn't all that difficult!
make && ./output
works. Git works from it. Also with clink (https://mridgers.github.io/clink/ ) it becomes even more similar. But you're right: For the times where you need more, you should fire up MSYS2 for example.I can't count how often I relaunch Command Prompt to Run as Admin.
But I'm hesitant to use a third party tool here, I really wish Microsoft just dealt with this properly.
Also, not sure why you've received two replies, that are - as far as I can see, completely irrelevant to what you've written; it's bizarre.
2 - Select Run As...
I'm author. I added this because I want to write hosts file with ":w !sudo tee %" from gvim.exe on Windows. But most of implementations doesn't work for this.
It's annoying that you still have to navigate the UAC dialog though - not sure how to get around that, without compromising security.
For those talking about right-click on the EXE... If you live in the command prompt, having to reach for the mouse just to elevate is irritating as hell.
0: https://www.reddit.com/r/netsec/comments/6e1uft/a_poc_demons...
Does your "something identical in 10 lines" do that?
I disagree, that's just an additional feature of it. The main point is that you can carry out admin tasks from an otherwise more restricted environment, so you only elevate your power when necessary. Otherwise, users might be tempted to always run whole sessions as an admin/root for convenience.
`Start-Process <stuff> -verb RunAs` does the same
For those without much Windows GUI-fu, shift-right click.
RunAs always asks for password for the Administrator account (not the account for the delegated account like sudo). I have admin access to my work PC, but not the Administrator password (since UAC grants me access). Also, running elevated programs always in separate windows, so you can't redirect their input/output. And CLI program disappear instantly (no time to read the output).
I have used elevate.exe (http://code.kliu.org/misc/elevate/) but sudo seems even better (supports redirecting input/output).
I am not sure if I understand this. Does the machine have two different admin accounts, once of which you have access to?
Wait, then where does the whole UAC thing comes from??
This solves a real problem and it works great. There's no horrible issue with getting a UAC dialog every time you do a sudo command. After all, in Windows (for better or worse) you need to be Administrator for less stuff.
cygstart --action=runas
This works well, too.alias sudo="cygstart --action=runas"
(and it would spare two key strokes ;)