
そのディレクトリで簡単に開きたい
PCを使ってると、ときたまコマンドプロンプトや、PowerShellをどこかのフォルダで開きたい。しかし、 + R で cmd や、タスクバーにピン止めしたものから起動すると、ディレクトリを移動するのが面倒。
そのフォルダで簡単に、しかも管理者権限で開きたい。そこで、右クリックで簡単に起動できちゃうようレジストリに追加しました。
コマンドプロンプト (管理者権限)
以下をレジストリに加えます。テキストエディタに貼り付け、UTF-8 (BOM付き) で拡張子を .reg にしてダブルクリック。
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Background\shell\CommandPromptAdmin]
@="CommandPrompt (Admin)"
"Icon"="cmd.exe"
"NoWorkingDirectory"=""
"HasLUAShield"=""
[HKEY_CLASSES_ROOT\Directory\Background\shell\CommandPromptAdmin\command]
@="powershell.exe -Command \"Start-Process 'cmd.exe' -ArgumentList '/s','/k','pushd \"%V\"' -Verb RunAs\""
[HKEY_CLASSES_ROOT\Directory\shell\CommandPromptAdmin]
@="CommandPrompt (Admin)"
"Icon"="cmd.exe"
"HasLUAShield"=""
[HKEY_CLASSES_ROOT\Directory\shell\CommandPromptAdmin\command]
@="powershell.exe -Command \"Start-Process 'cmd.exe' -ArgumentList '/s','/k','pushd \"%1\"' -Verb RunAs\""
PowerShell 7 (管理者権限)
PowerShell 7 は以下をレジストリに加えます。PowerShell 7 未導入であれば、こちらを参考に。
PowerShellをアップデートする (ガジェマル)
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Background\shell\PowerShell7Admin]
@="PowerShell 7 (Admin)"
"Icon"="C:\\Program Files\\PowerShell\\\pwsh.exe"
"NoWorkingDirectory"=""
"HasLUAShield"=""
[HKEY_CLASSES_ROOT\Directory\Background\shell\PowerShell7Admin\command]
@="powershell.exe -Command \"Start-Process 'C:\\Program Files\\PowerShell\\7\\pwsh.exe' -ArgumentList '-NoExit','-Command','Set-Location -LiteralPath ''%V''' -Verb RunAs\""
[HKEY_CLASSES_ROOT\Directory\shell\PWSH7Admin]
@="PowerShell 7 (Admin)"
"Icon"="pwsh.exe"
"HasLUAShield"=""
[HKEY_CLASSES_ROOT\Directory\shell\PWSH7Admin\command]
@="powershell.exe -Command \"Start-Process 'pwsh.exe' -ArgumentList '-NoExit','-Command','Set-Location \"%1\"' -Verb RunAs\""
これで、目的のフォルダか、フォルダを開いた空白の部分かを Shift + 右クリック すると以下のようにメニューが出るので、項目を選びます。

すると、以下のようにそのディレクトリでプロンプトが管理者権限で開きます。便利!
D:\Temp\Work>