「管理者としてここにPowerShellを開く」オプションをフォルダのコンテキストメニューに追加します


15

私は、プロンプトでを開きたいフォルダのコンテキストメニューから、直接Windowsエクスプローラからの迅速な上昇PowerShellを開くための方法を探してきた。
私は、Windows 10を使用して、私がこれまで持って見てきたすべての例です古いバージョンのWindows用です。以前、これはWindows 8.1で機能していましたが、10への更新で壊れました。私はこれをWindows 10でも簡単に機能させることができましたが、アップデートにより再び壊れました(2015年12月)。

この機能をWindowsに追加する正しい方法を知っている人はいますか?それとも、将来のWindowsの更新によって上書きされる運命にありますか?

回答:


20

これは、現在この機能をWindowsエクスプローラーのコンテキストメニューに追加する唯一の方法です。

[このスクリプトを管理者特権のプロンプトで実行する]

$menu = 'Open Windows PowerShell Here as Administrator'
$command = "$PSHOME\powershell.exe -NoExit -NoProfile -Command ""Set-Location '%V'"""

'directory', 'directory\background', 'drive' | ForEach-Object {
    New-Item -Path "Registry::HKEY_CLASSES_ROOT\$_\shell" -Name runas\command -Force |
    Set-ItemProperty -Name '(default)' -Value $command -PassThru |
    Set-ItemProperty -Path {$_.PSParentPath} -Name '(default)' -Value $menu -PassThru |
    Set-ItemProperty -Name HasLUAShield -Value ''
}

次のリンクから取られたこのスクリプト:

http://www.powershellmagazine.com/2013/06/25/pstip-how-to-start-an-elevated-powershell-from-windows-explorer/

これは、最新のWindowsパッチがレジストリ設定を「削除」する前に行った方法であることは99%確信しています(numlockブートステータスなどの他のカスタマイズも削除しましたが、面倒ではありません)。

誰かがより良いアプローチを知っている場合; つまり、それは揮発性ではないので、教えてください。その答えを受け入れます。


1
確かに、Windows 10はUACの問題です。「無効」であっても、それは絶え間ない頭痛です。Windows 7に戻っていない唯一の理由は、4つの画面があるからです。
致命的なバーゲル

4
-NoProfileスイッチを削除すると、プロンプトを起動したときにプロファイルが自動的にロードされます。
イアン・ケンプ

あなたは、「管理者として実行スクリプト」を追加したい場合は、PS1のコンテキスト・メニュー・オプションは、ファイル自体のことに注意してください、どのようにこの回答ショーのセクション2:stackoverflow.com/a/57033941/2441655
Venryx

1

私はこのようにしてきました。それは私が作った小さなメニューの一部です。お好みに合わせて編集してください:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\OAPS.Tools]
"ImpliedSelectionModel"=dword:00000001
"Icon"="imageres.dll,-5373"
"ExplorerCommandHandler"="{BF0AC53F-D51C-419F-92E3-2298E125F004}"
@="Admin Pshell Here"

0

Windows 10の任意のフォルダーのバックグラウンドコンテキストメニューにCMDとPOWERSHELLの両方を追加するために使用するregファイルのコピーを次に示します。

Windows Registry Editor Version 5.00

;Add_Open_CMD_and_Powershell_to_Context_Menu.reg

;Right-Click Background only

;CMD Prompt

[HKEY_CLASSES_ROOT\Directory\Background\shell\01MenuCmd] "MUIVerb"="Command Prompts" "Icon"="cmd.exe" "ExtendedSubCommandsKey"="Directory\Background\ContextMenus\MenuCmd"

[HKEY_CLASSES_ROOT\Directory\Background\shell\01MenuCmd] "MUIVerb"="Command Prompts" "Icon"="cmd.exe" "ExtendedSubCommandsKey"="Directory\Background\ContextMenus\MenuCmd"

[HKEY_CLASSES_ROOT\Directory\Background\ContextMenus\MenuCmd\shell\open] "MUIVerb"="Command Prompt" "Icon"="cmd.exe"

[HKEY_CLASSES_ROOT\Directory\Background\ContextMenus\MenuCmd\shell\open\command] @="cmd.exe /s /k pushd \"%V\""

[HKEY_CLASSES_ROOT\Directory\Background\ContextMenus\MenuCmd\shell\runas] "MUIVerb"="Command Prompt Elevated" "Icon"="cmd.exe" "HasLUAShield"=""

[HKEY_CLASSES_ROOT\Directory\Background\ContextMenus\MenuCmd\shell\runas\command] @="cmd.exe /s /k pushd \"%V\""

; PowerShell

[HKEY_CLASSES_ROOT\Directory\Background\shell\02MenuPowerShell] "MUIVerb"="PowerShell Prompts" "Icon"="powershell.exe" "ExtendedSubCommandsKey"="Directory\Background\ContextMenus\MenuPowerShell"

[HKEY_CLASSES_ROOT\Directory\Background\shell\02MenuPowerShell] "MUIVerb"="PowerShell Prompts" "Icon"="powershell.exe" "ExtendedSubCommandsKey"="Directory\Background\ContextMenus\MenuPowerShell"

[HKEY_CLASSES_ROOT\Directory\Background\ContextMenus\MenuPowerShell\shell\open] "MUIVerb"="PowerShell" "Icon"="powershell.exe"

[HKEY_CLASSES_ROOT\Directory\Background\ContextMenus\MenuPowerShell\shell\open\command] @="powershell.exe -noexit -command Set-Location '%V'"

[HKEY_CLASSES_ROOT\Directory\Background\ContextMenus\MenuPowerShell\shell\runas] "MUIVerb"="PowerShell Elevated" "Icon"="powershell.exe" "HasLUAShield"=""

[HKEY_CLASSES_ROOT\Directory\Background\ContextMenus\MenuPowerShell\shell\runas\command] @="powershell.exe -noexit -command Set-Location '%V'"

弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.