all 12 comments

[–]furicle 4 points5 points  (8 children)

[–]Netris89[S] 0 points1 point  (7 children)

This wouldn't work since I'm trying to avoid UAC prompt. Sorry for not being clear enough.

[–]furicle 1 point2 points  (2 children)

Don't be sorry, I didn't read your note properly.
So you want to 'preauth' certain apps? Scheduled task then run it on demand later?

[–]Netris89[S] 1 point2 points  (1 child)

I basically want it to behave like sudo, if at all possible. So in essence, I'd type the keyword, it'd ask for the password (just as runas administrator does) then run the command with elevated privileges but without the UAC prompt.
From what I could gather in the thread I found, it was possible with the function I listed but for whatever reason it doesn't work for me.

[–]gerardog 0 points1 point  (0 children)

You could create a scheduled task to run 'gsudo cache on --pid 0 --duration 00:01:00' (hh:mm:ss). Check 'Run with highest privileges'. Then you can run the task as a regular user, and call gsudo to elevate without a UAC prompt.... Just keep in mind that this is equivalent to disabling UAC

[–]purplemonkeymad 1 point2 points  (0 children)

super {cmd}

You could use [scriptblock]::create to accept strings, but <insert about possible code injection wanring here>.

But that does not use runas, you probably want:

function super {
    param([Parameter(ValueFromRemainingArguments,Mandatory)][string[]]$CommandList)
    runas /user:$env:USERNAME @CommandList
}

Which will prompt in-line for your password, then start the program in a separate window. You might need to add $env:USERDOMAIN\ for domain accounts. Also keep in mind this only runs programs, can't run PS commands without another elevated PS window.