0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

フォルダの Shift-右クリックで WSL2 を起動する「Ubuntu Here」

Last updated at Posted at 2025-03-07

フォルダの Shift-右クリックで WSL2 の Ubuntu を起動する「Ubuntu Here」

Windows のフォルダーを指定して Shift-右クリックで WSL2 の Ubuntsu のシェルを起動する Ubuntu Here を作りました。この右クリックメニューは Microsoft PowerToys に付属の Open Command Window Here を修正して作成しています。

Ubuntuhere.inf のコード

以下のテキストで Ubuntuhere.inf を作成します。
作成したファイルを右クリックしてインストールします。
この inf ファイルはアンインストールに対応しています。

Ubuntuhere.inf
[Version]
Signature=$CHICAGO$

[DefaultInstall]
AddReg=Reg.Settings
AddReg=Reg.Uninstall
CopyFiles=Inf.Copy

[DefaultUninstall]
DelReg=Reg.Settings
DelReg=Reg.Uninstall
DelFiles=Inf.Copy

[Reg.Settings]
HKCR,Directory\Shell\Ubuntuhere
HKCR,Directory\Shell\Ubuntuhere,,,"%MENUITEM%"
HKCR,Directory\Shell\Ubuntuhere\command,,,"%11%\cmd.exe /c ""cd """"%1"""" && wsl -d Ubuntu-24.04"""
HKCR,Drive\Shell\Ubuntuhere
HKCR,Drive\Shell\Ubuntuhere,,,"%MENUITEM%"
HKCR,Drive\Shell\Ubuntuhere\command,,,"%11%\cmd.exe /c ""cd """"%1"""" && wsl -d Ubuntu-24.04"""

[Reg.Uninstall]
HKLM,Software\Microsoft\Windows\CurrentVersion\Uninstall\%NAME%
HKLM,Software\Microsoft\Windows\CurrentVersion\Uninstall\%NAME%,DisplayName,,"%NAME%"
HKLM,Software\Microsoft\Windows\CurrentVersion\Uninstall\%NAME%,UninstallString,,"Rundll32.exe setupapi.dll,InstallHinfSection DefaultUninstall 132 %17%\Ubuntuhere.inf"

[Inf.Copy]
Ubuntuhere.inf

[DestinationDirs]
Inf.Copy=17

[SourceDisksNames]
55=%DISKNAME%

[SourceDisksFiles]
Ubuntuhere.inf=55

[Strings]
NAME     = "Ubuntu Here"
MENUITEM = "Ubuntu Here"
DISKNAME = "Setup Files"

フォルダーの Shit-右クリックで起動

フォルダーの Shift-右クリックのメニューで Ubuntu Here を選択すると WSL2 の Ubuntu の Shell が起動します。

Shift-右クリックメニュー

起動したWSLのShell

カスタマイズ方法

独自のコマンドを右クリックで実行するためのカスタマイズ方法の解説です。この修正方法を使うと powershell を起動する右クリックメニューなども作成可能です。

1. 右クリックの名前変更

Ubuntu Hereを検索して置換します。例えばUbuntu 20.04に置換します。

2. inf ファイル名の変更

Ubuntuhere.infを検索して置換します。例えばUbuntu20_04.infに置換します。ファイル名もUbuntu20_04.infに変更します

3. 右クリックで実行するコマンドの変更

"%11%\cmd.exe /c ""cd """"%1"""" && wsl -d Ubuntu-24.04"""を検索して置換します。例えば"%11%\cmd.exe /c ""cd """"%1"""" && wsl -d Ubuntu-20.04"""に置換します。
コマンドの記述方法について、%1は右クリックしたフォルダ名です。"ダブルクオートをコマンドに含める場合は、""二つのダブルクオートを使用します。上のコマンドはcmd.exe /c "cd ""%1"" && wsl -d Ubuntu-20.04"が元のコマンドです。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?