Warning: Cannot modify header information - headers already sent by (output started at /home/fantasmo/public_html/ash.wine/wp-content/plugins/jetpack/jetpack.php:1) in /home/fantasmo/public_html/ash.wine/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/fantasmo/public_html/ash.wine/wp-content/plugins/jetpack/jetpack.php:1) in /home/fantasmo/public_html/ash.wine/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/fantasmo/public_html/ash.wine/wp-content/plugins/jetpack/jetpack.php:1) in /home/fantasmo/public_html/ash.wine/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/fantasmo/public_html/ash.wine/wp-content/plugins/jetpack/jetpack.php:1) in /home/fantasmo/public_html/ash.wine/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/fantasmo/public_html/ash.wine/wp-content/plugins/jetpack/jetpack.php:1) in /home/fantasmo/public_html/ash.wine/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/fantasmo/public_html/ash.wine/wp-content/plugins/jetpack/jetpack.php:1) in /home/fantasmo/public_html/ash.wine/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/fantasmo/public_html/ash.wine/wp-content/plugins/jetpack/jetpack.php:1) in /home/fantasmo/public_html/ash.wine/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/fantasmo/public_html/ash.wine/wp-content/plugins/jetpack/jetpack.php:1) in /home/fantasmo/public_html/ash.wine/wp-includes/rest-api/class-wp-rest-server.php on line 1775
{"id":284,"date":"2016-06-28T14:33:00","date_gmt":"2016-06-28T09:03:00","guid":{"rendered":"http:\/\/ash.wine\/?p=284"},"modified":"2016-11-18T15:27:40","modified_gmt":"2016-11-18T09:57:40","slug":"open-powershell-as-admin-on-right-click-context-menu","status":"publish","type":"post","link":"http:\/\/hacks.ash.wine\/open-powershell-as-admin-on-right-click-context-menu\/","title":{"rendered":"Open Powershell as Admin on Right-Click (Context Menu)"},"content":{"rendered":"
\n

\n<\/span><\/a>Open Powershell as Admin on Right-Click<\/h1>\n

I described how to set a context menu option<\/a> to open a Powershell console on right click earlier.<\/p>\n

To open Powershell as admin on right click, we can add a command to be executed on start to our registry entry like so<\/p>\n

\n
$stpath<\/span> = pwd<\/span>;<\/span> Start-Process PowerShell -ArgumentList \\\"<\/span>-NoExit\\\"<\/span>, \\\"<\/span>-Command cd<\/span> $stpath<\/span>\\\"<\/span> -verb RunAs<\/pre>\n<\/div>\n

So our Command<\/code> in the registry entry will look like the following<\/p>\n

\n
\"<\/span>C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\"<\/span><\/span> -windowstyle hidden -Command $stpath<\/span> = pwd<\/span>;<\/span> Start-Process PowerShell -ArgumentList \\\"<\/span>-NoExit\\\"<\/span>, \\\"<\/span>-Command cd<\/span> $stpath<\/span>\\\"<\/span> -verb RunAs<\/pre>\n<\/div>\n

The downside of this approach is that first a normal Powershell window is opened, which opens a new Powershell window as admin if the user has the priviledges, and then the original Powershell window closes in the background.<\/p>\n

This results in a flicker when Powershell is run as admin. \ud83d\ude22<\/g-emoji><\/p>\n

\"Run<\/a><\/p>\n

If you find a flickerless approach to doing this, please leave a comment on this gist<\/a>. Thanks!<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"

Open Powershell as Admin on Right-Click I described how to set a context menu option to open a Powershell console on right click earlier. To open Powershell as admin on right click, we can add a command to be executed on start to our registry entry like so $stpath = pwd; Start-Process PowerShell -ArgumentList \\”-NoExit\\”, […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[22,21],"_links":{"self":[{"href":"http:\/\/ash.wine\/wp-json\/wp\/v2\/posts\/284"}],"collection":[{"href":"http:\/\/ash.wine\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ash.wine\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ash.wine\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ash.wine\/wp-json\/wp\/v2\/comments?post=284"}],"version-history":[{"count":1,"href":"http:\/\/ash.wine\/wp-json\/wp\/v2\/posts\/284\/revisions"}],"predecessor-version":[{"id":285,"href":"http:\/\/ash.wine\/wp-json\/wp\/v2\/posts\/284\/revisions\/285"}],"wp:attachment":[{"href":"http:\/\/ash.wine\/wp-json\/wp\/v2\/media?parent=284"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ash.wine\/wp-json\/wp\/v2\/categories?post=284"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ash.wine\/wp-json\/wp\/v2\/tags?post=284"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}