hack のためのネタ帳, etc,,,

×

状況

Windows 11 で任意のフォルダに cd した状態で WSL の Ubuntu が WindowsTerminal で開くように以下の設定
$icon=Get-AppxPackage|? Name -m Ubuntu|% {"$($_.InstallLocation)\$(($_|Get-AppPackageManifest).Package.Applications.Application.Executable)"} ;
New-Item         -Force -Path Registry::HKCU\SOFTWARE\Classes\Drive\Shell\WSLUbuntuHere
New-Item         -Force -Path Registry::HKCU\SOFTWARE\Classes\Drive\Shell\WSLUbuntuHere\command
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Drive\Shell\WSLUbuntuHere                        -Name "(Default)" -PropertyType ExpandString -Value "WSL Ubuntu here"
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Drive\Shell\WSLUbuntuHere                        -Name Icon        -PropertyType ExpandString -Value "`"$icon`""
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Drive\Shell\WSLUbuntuHere\command                -Name "(Default)" -PropertyType ExpandString -Value "`"%LOCALAPPDATA%\Microsoft\WindowsApps\wt.exe`" -d `"%L`" -p Ubuntu"
New-Item         -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Shell\WSLUbuntuHere
New-Item         -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Shell\WSLUbuntuHere\command
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Shell\WSLUbuntuHere                    -Name "(Default)" -PropertyType ExpandString -Value "WSL Ubuntu here"
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Shell\WSLUbuntuHere                    -Name Icon        -PropertyType ExpandString -Value "`"$icon`""
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Shell\WSLUbuntuHere\command            -Name "(Default)" -PropertyType ExpandString -Value "`"%LOCALAPPDATA%\Microsoft\WindowsApps\wt.exe`" -d `"%L`" -p Ubuntu"
New-Item         -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Background\Shell\WSLUbuntuHere
New-Item         -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Background\Shell\WSLUbuntuHere\command
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Background\Shell\WSLUbuntuHere         -Name "(Default)" -PropertyType ExpandString -Value "WSL Ubuntu here"
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Background\Shell\WSLUbuntuHere         -Name Icon        -PropertyType ExpandString -Value "`"$icon`""
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Background\Shell\WSLUbuntuHere\command -Name "(Default)" -PropertyType ExpandString -Value "`"%LOCALAPPDATA%\Microsoft\WindowsApps\wt.exe`" -d .      -p Ubuntu"
をしていたのだが、WSL Ubuntu here してもなぜか PowerShell が開いてしまう。
例えばデスクトップに置いた tmp に対して WSL Ubuntu here すると
Microsoft Windows [Version 10.0.26200.7171]
(c) Microsoft Corporation. All rights reserved.

C:\Users\kou\Desktop\tmp>
みたいになる。

また、上記のレジストリで登録されて項目にアイコンが表示されないのも気になる点。

原因

WindowsTerminal の設定を確認してみると Ubuntu のエントリが二つに増えていた。

一つ目は
このプロファイルは検出されなくなりました
この自動的に検出されたプロファイルはアンインストールされた可能性があります。行った変更は保存されますが、再インストールされるまでは使用できません。
[プロファイルの削除]

名前
ドロップダウンに表示されるプロファイルの名前です。
Ubuntu

元のソース
このプロファイルを最初に作成したソフトウェアを示します。
Windows.Terminal.Wsl
となってて、どうもこれが検出できないため、PowerShell に fallback されてる模様。
二つ目の有効な方のは、
名前
ドロップダウンに表示されるプロファイルの名前です。
Ubuntu

コマンドライン
このプロファイルで使用される実行可能ファイル
C:\WINDOWS\system32\wsl.exe --distribution-id {97705b03-93f3-4c13-88b7-eb8c228cbb3a} --cd ~

開始ディレクトリ
プロファイルが読み込まれたときに開始されるディレクトリです。
☑親プロセス ディレクトリの使用

アイコン
プロファイルで使用されるアイコンの絵文字またはイメージ ファイルの場所です。
C:\Users\kou\AppData\Local\wsl\{97705b03-93f3-4c13-88b7-eb8c228cbb3a}\shortcut.ico

...
みたいな感じ。

WSL のイメージが、前は、
  • %LOCALAPPDATA%\Packages\CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc\LocalState\ext4.vhdx
辺りにあったはずなのだが(see: 20250804: Windows 11 - disk cleanup)
なんか、いつの間にかアイコンと同じフォルダ
  • %LOCALAPPDATA%\wsl\{97705b03-93f3-4c13-88b7-eb8c228cbb3a}\ext4.vhdx
に移動してた。

更に、WSL やら Ubuntu やらが Get-AppxPackage から消えてて、どこに行ったのか不明。
Ubuntu のイメージはどこなんだろう?これか?
  • C:\Program Files\WSL\system.vhd : 388.4 MB
  • C:\Program Files\WSL\tools\modules.vhd : 186.0 MB

WSL 本体は Appx じゃなくて MSIX の方にあったが、Ubuntu は見当たらない。
PS C:\Users\kou> Get-MsixPackage |? Name -m linux


Name              : MicrosoftCorporationII.WindowsSubsystemForLinux
Publisher         : CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US
Architecture      : X64
ResourceId        :
Version           : 2.5.7.0
PackageFullName   : MicrosoftCorporationII.WindowsSubsystemForLinux_2.5.7.0_x64__8wekyb3d8bbwe
InstallLocation   : C:\Program Files\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_2.5.7.0_x64__8wekyb3d8
                    bbwe
IsFramework       : False
PackageFamilyName : MicrosoftCorporationII.WindowsSubsystemForLinux_8wekyb3d8bbwe
PublisherId       : 8wekyb3d8bbwe
IsResourcePackage : False
IsBundle          : False
IsDevelopmentMode : False
NonRemovable      : False
IsPartiallyStaged : False
SignatureKind     : Developer
Status            : Ok



wsl --list で列挙される WSL に install 済みの Distribution については以下のようにすると参照できた。
ls Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Lxss |% {"$($_.PSChildName)`t$(gpv $_.PSPAth DistributionName)"}
結果
PS C:\Users\kou> ls Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Lxss |% {"$($_.PSChildName)`t$(gpv $_.PSPAth DistributionName)"}
{97705b03-93f3-4c13-88b7-eb8c228cbb3a}  Ubuntu

とりあえず、Windows Terminal の設定は

%LOCALAPPDATA%\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json

{
    "$help": "https://aka.ms/terminal-documentation",
    "$schema": "https://aka.ms/terminal-profiles-schema",
    "actions": [],
    "copyFormatting": "none",
    "copyOnSelect": false,
    "defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
    "keybindings":
    [
        {
            "id": "Terminal.CopyToClipboard",
            "keys": "ctrl+c"
        },
        {
            "id": "Terminal.FindText",
            "keys": "ctrl+shift+f"
        },
        {
            "id": "Terminal.PasteFromClipboard",
            "keys": "ctrl+v"
        },
        {
            "id": "Terminal.DuplicatePaneAuto",
            "keys": "alt+shift+d"
        }
    ],
    "newTabMenu":
    [
        {
            "type": "remainingProfiles"
        }
    ],
    "profiles":
    {
        "defaults": {},
        "list":
        [
            {
                "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
                "hidden": false,
                "name": "Windows PowerShell"
            },
            {
                "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
                "hidden": false,
                "name": "\u30b3\u30de\u30f3\u30c9 \u30d7\u30ed\u30f3\u30d7\u30c8"
            },
            {
                "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
                "hidden": false,
                "name": "Azure Cloud Shell",
                "source": "Windows.Terminal.Azure"
            },
            {
                "guid": "{2c4de342-38b7-51cf-b940-2309a097f518}",
                "hidden": true,
                "name": "Ubuntu",
                "source": "Windows.Terminal.Wsl"
            },
            {
                "guid": "{445d2a20-8671-52d8-800e-f67fe8d03f95}",
                "hidden": false,
                "name": "Ubuntu",
                "source": "Microsoft.WSL"
            }
        ]
    },
    "schemes": [],
    "themes": []
}
Profile は

%LOCALAPPDATA%\Microsoft\Windows Terminal\Fragments\Microsoft.WSL\{445d2a20-8671-52d8-800e-f67fe8d03f95}.json

PS C:\Users\kou> cat $ENV:LOCALAPPDATA\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json
{
    "$help": "https://aka.ms/terminal-documentation",
    "$schema": "https://aka.ms/terminal-profiles-schema",
    "actions": [],
    "copyFormatting": "none",
    "copyOnSelect": false,
    "defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
    "keybindings":
    [
        {
            "id": "Terminal.CopyToClipboard",
            "keys": "ctrl+c"
        },
        {
            "id": "Terminal.FindText",
            "keys": "ctrl+shift+f"
        },
        {
            "id": "Terminal.PasteFromClipboard",
            "keys": "ctrl+v"
        },
        {
            "id": "Terminal.DuplicatePaneAuto",
            "keys": "alt+shift+d"
        }
    ],
    "newTabMenu":
    [
        {
            "type": "remainingProfiles"
        }
    ],
    "profiles":
    {
        "defaults": {},
        "list":
        [
            {
                "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
                "hidden": false,
                "name": "Windows PowerShell"
            },
            {
                "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
                "hidden": false,
                "name": "\u30b3\u30de\u30f3\u30c9 \u30d7\u30ed\u30f3\u30d7\u30c8"
            },
            {
                "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
                "hidden": false,
                "name": "Azure Cloud Shell",
                "source": "Windows.Terminal.Azure"
            },
            {
                "guid": "{2c4de342-38b7-51cf-b940-2309a097f518}",
                "hidden": true,
                "name": "Ubuntu",
                "source": "Windows.Terminal.Wsl"
            },
            {
                "guid": "{445d2a20-8671-52d8-800e-f67fe8d03f95}",
                "hidden": false,
                "name": "Ubuntu",
                "source": "Microsoft.WSL"
            }
        ]
    },
    "schemes": [],
    "themes": []
}
にあった。

解法

とりあえず、Windows Terminal の設定から無効になってる一つ目の Ubuntu を削除してみたところ、
繰り上がった二つ目の Ubuntu が呼ばれるようになって解決した。

とりあえず、WSL Ubuntu here の 1 行目を変更して以下のようにしておくのがよさそう。
$icon=(ls Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Lxss |% PSPath | gp |% {@{($_.DistributionName)=(get-childitem $_.BasePath shortcut.ico)}} |% {$_["Ubuntu"].FullName})
New-Item         -Force -Path Registry::HKCU\SOFTWARE\Classes\Drive\Shell\WSLUbuntuHere
New-Item         -Force -Path Registry::HKCU\SOFTWARE\Classes\Drive\Shell\WSLUbuntuHere\command
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Drive\Shell\WSLUbuntuHere                        -Name "(Default)" -PropertyType ExpandString -Value "WSL Ubuntu here"
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Drive\Shell\WSLUbuntuHere                        -Name Icon        -PropertyType ExpandString -Value "`"$icon`""
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Drive\Shell\WSLUbuntuHere\command                -Name "(Default)" -PropertyType ExpandString -Value "`"%LOCALAPPDATA%\Microsoft\WindowsApps\wt.exe`" -d `"%L`" -p Ubuntu"
New-Item         -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Shell\WSLUbuntuHere
New-Item         -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Shell\WSLUbuntuHere\command
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Shell\WSLUbuntuHere                    -Name "(Default)" -PropertyType ExpandString -Value "WSL Ubuntu here"
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Shell\WSLUbuntuHere                    -Name Icon        -PropertyType ExpandString -Value "`"$icon`""
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Shell\WSLUbuntuHere\command            -Name "(Default)" -PropertyType ExpandString -Value "`"%LOCALAPPDATA%\Microsoft\WindowsApps\wt.exe`" -d `"%L`" -p Ubuntu"
New-Item         -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Background\Shell\WSLUbuntuHere
New-Item         -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Background\Shell\WSLUbuntuHere\command
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Background\Shell\WSLUbuntuHere         -Name "(Default)" -PropertyType ExpandString -Value "WSL Ubuntu here"
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Background\Shell\WSLUbuntuHere         -Name Icon        -PropertyType ExpandString -Value "`"$icon`""
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Background\Shell\WSLUbuntuHere\command -Name "(Default)" -PropertyType ExpandString -Value "`"%LOCALAPPDATA%\Microsoft\WindowsApps\wt.exe`" -d .      -p Ubuntu"

コメントをかく


「http://」を含む投稿は禁止されています。

利用規約をご確認のうえご記入下さい

Wiki内検索

フリーエリア

管理人/副管理人のみ編集できます

広告募集中