Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wslview fails when registry access is disabled #291

Closed
1 task done
jaknz opened this issue Oct 18, 2023 · 4 comments
Closed
1 task done

wslview fails when registry access is disabled #291

jaknz opened this issue Oct 18, 2023 · 4 comments
Assignees
Labels
Bug This is either an issue that describes a bug or a PR that resolves a bug Status: Patched This is fixed and is part of a released version. Target: 4.x This is targeted to the 4.x release.

Comments

@jaknz
Copy link

jaknz commented Oct 18, 2023

Windows Version

Windows 11

Windows Build Number

22621.2428

WSL Version

WSL 2

Distro Version

Debian 12

WSL Utilities Version

4.1.1

Describe the bug

On a corporate GPO-managed Windows workstation where group policy prohibits access to the registry, multiple calls to reg.exe fail with errors, leading to internal failures in the utility and broken functionality. Pages do load in my Windows browser, so obviously these calls to the registry aren't core to the functionality. Would be really great to either not depend on REG at all, or have an option flag to not check whatever it is trying to check.

Steps to Reproduce

$ wslview "http://github.com"

Expected behavior

Script runs quietly and launches Windows web browser, without several lines of error messages.

Additional context

Error stream output from script:

ERROR: Registry editing has been disabled by your administrator.
ERROR: Registry editing has been disabled by your administrator.
ERROR: Registry editing has been disabled by your administrator.
/usr/bin/wslview: line 267: [: : integer expression expected
Parameter format not correct - ""
Cannot find an overload for "GetEncoding" and the argument count: "0".
At line:1 char:59
+ ... ing]::UTF8; [Console]::InputEncoding = [System.Text.Encoding]::GetEnc ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

/usr/bin/wslview: line 270: [: : integer expression expected

Code of Conduct

  • I agree to follow this project's Code of Conduct
@jaknz jaknz added the Bug This is either an issue that describes a bug or a PR that resolves a bug label Oct 18, 2023
@jaknz jaknz changed the title wslview failes when registry access is disabled wslview fails when registry access is disabled Oct 18, 2023
@jaknz
Copy link
Author

jaknz commented Oct 18, 2023

I found the --debug flag in the code for slightly more info:

[debug:/usr/bin/wslview] Showing debug output.
[debug:/usr/bin/wslview] source default setting
[debug:/usr/bin/wslview] /etc/wslu/conf found, sourcing
ERROR: Registry editing has been disabled by your administrator.
[debug:/usr/bin/wslview] distro: debian
[debug:/usr/bin/wslview] lname: https://github.com
[debug:/usr/bin/wslview] WSLVIEW_DEFAULT_ENGINE: powershell
ERROR: Registry editing has been disabled by your administrator.
[debug:/usr/bin/wslview] properfile_full_path:
[debug:/usr/bin/wslview] validating whether if it is a link
[debug:/usr/bin/wslview] It is a link
[debug:/usr/bin/wslview] cmd: "https://github.com"
[debug:/usr/bin/wslview] winps_exec: called with command Start "https://github.com"
ERROR: Registry editing has been disabled by your administrator.
/usr/bin/wslview: line 267: [: : integer expression expected
Parameter format not correct - ""
Cannot find an overload for "GetEncoding" and the argument count: "0".
At line:1 char:59
+ ... ing]::UTF8; [Console]::InputEncoding = [System.Text.Encoding]::GetEnc ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

/usr/bin/wslview: line 270: [: : integer expression expected

@jaknz
Copy link
Author

jaknz commented Oct 18, 2023

I've been walking through the code to see what can be done without checking the registry. Looks like the biggest offender is getting the Windows build number. I've found a reliable fallback which I've patched into my installed version, and it's much quieter, but not completely error-free.

build=$("$(interop_prefix)$(sysdrive_prefix)"/Windows/System32/WindowsPowerShell/v1.0/powershell.exe /c "(gcm wsl).Version.Build" | sed -e 's|\r||g')

@jaknz
Copy link
Author

jaknz commented Oct 18, 2023

It also looks like the codepage variable isn't being set which is causing the Powershell errors. This can also be handled by (ironically) calling Powershell as above:

cp=$("$(interop_prefix)$(sysdrive_prefix)"/Windows/System32/WindowsPowerShell/v1.0/powershell.exe /c "Get-ItemPropertyValue HKLM:\SYSTEM\CurrentControlSet\Control\Nls\CodePage -Name OEMCP" | sed -e 's|\r||g')

@jaknz
Copy link
Author

jaknz commented Oct 18, 2023

And with those two patches, I'm not hitting reg.exe, and thus getting a clean run. Note that I added a couple of debug_echo commands to check that I'm getting the correct build and codepage with these new methods.

wslview --debug "http://github.com"
[debug:/usr/bin/wslview-patch] Showing debug output.
[debug:/usr/bin/wslview-patch] source default setting
[debug:/usr/bin/wslview-patch] /etc/wslu/conf found, sourcing
[debug:/usr/bin/wslview-patch] build: 22621
[debug:/usr/bin/wslview-patch] distro: debian
[debug:/usr/bin/wslview-patch] lname: http://github.com
[debug:/usr/bin/wslview-patch] WSLVIEW_DEFAULT_ENGINE: powershell
[debug:/usr/bin/wslview-patch] build: 22621
[debug:/usr/bin/wslview-patch] properfile_full_path:
[debug:/usr/bin/wslview-patch] validating whether if it is a link
[debug:/usr/bin/wslview-patch] It is a link
[debug:/usr/bin/wslview-patch] cmd: "http://github.com"
[debug:/usr/bin/wslview-patch] winps_exec: called with command Start "http://github.com"
[debug:/usr/bin/wslview-patch] build: 22621
[debug:/usr/bin/wslview-patch] codepage: 850

@patrick330602 patrick330602 added Status: In Progress This is being worked on and not ready. Target: 4.x This is targeted to the 4.x release. labels Nov 12, 2023
@patrick330602 patrick330602 added Status: Pending Release This is fixed but not yet released. and removed Status: In Progress This is being worked on and not ready. labels Dec 31, 2023
@patrick330602 patrick330602 added Status: Patched This is fixed and is part of a released version. and removed Status: Pending Release This is fixed but not yet released. labels Mar 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This is either an issue that describes a bug or a PR that resolves a bug Status: Patched This is fixed and is part of a released version. Target: 4.x This is targeted to the 4.x release.
Projects
None yet
Development

No branches or pull requests

2 participants