1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

WindowsTerminalにPowerShellを管理者実行で開くプロファイルを追加してみる(gsudo)

Posted at

下記画像赤枠のように、Windows TerminalでPowerShellを管理者実行で起動するようなプロファイルの書き方について。

image.png

事前準備

本記事ではgsudoコマンドを利用するため、下記記事にあるようにgsudoをインストールして下さい。

gsudoコマンドをつかって、WindowsのPowerShell上でいい感じに管理者権限を利用する

設定

Windows Terminalの設定から新しいプロファイルのを追加しますを選択

image.png

今回はPowerShellを管理者実行で開くプロファイルを追加したいので、複製元にPowerShellを選択して複製を選択

image.png

既存設定がコピーされました。

image.png

名前がコピーとなっているので、適当な名前をつけます。

コマンドラインは"C:\Program Files\PowerShell\7\pwsh.exe" となっていた部分を gsudo "C:\Program Files\PowerShell\7\pwsh.exe" とgsudo経由で起動するように変更。

名前とコマンドラインを変更したら、保存を選択

image.png

設定を反映させるため、一度windows Terminalを終了します。

image.png

Windows Terminalを起動すると先程設定したプロファイルに従い、管理者実行のPowreShell起動が追加されています。

image.png

このメニューから起動すると、gsudo経由でPowerShellが起動され管理者実行されたプロンプトが起動します。

image.png

上記画像は、.NETのWindowsPrincipal.IsInRole メソッドで管理者実行されているのを確認した図。

総評

gsudoコマンドがあるので、既存のプロンプトを昇格することが多いかと思いますが。
管理者実行のPowerShellプロンプトをもう一枚開きたいといったケースの場合、便利かと思います。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?