gerardog / gsudo

Sudo for Windows
https://gerardog.github.io/gsudo
MIT License
5.07k stars 136 forks source link

Error: `ParentContainsErrorRecordException` when using `gsudo { Get-NetIPAddress }` #341

Closed cloud-yu closed 4 months ago

cloud-yu commented 4 months ago

Issue Description

gsudo { Get-NetIPAddress } end up with an error

Steps to Reproduce

image

with --debug

Debug: Invoking Shell: PowerShellCore
Debug: Command Line: --debug -encodedCommand IABHAGUAdAAtAE4AZQB0AEkAUABBAGQAZAByAGUAcwBzACAA -inputFormat xml -outputFormat text
Debug: Applying workaround for target app installed via MSStore.
Debug: Command to run: C:\WINDOWS\system32\cmd.exe /v:on /s /c ""C:\Program Files\WindowsApps\Microsoft.PowerShell_7.4.1.0_x64__8wekyb3d8bbwe\pwsh.exe" -NoLogo -NoProfile -encodedCommand IABHAGUAdAAtAE4AZQB0AEkAUABBAGQAZAByAGUAcwBzACAA -inputFormat xml -outputFormat text"
Debug: Using Console mode TokenSwitch
Debug: Caller PID: 6140
Debug: Caller SID: S-1-5-21-3861694489-1318466560-650796685-1002
Debug: Elevating process: C:\Program Files\gsudo\2.4.4\gsudo.exe --debug gsudoelevate 6140 S-1-5-21-3861694489-1318466560-650796685-1002 All 00:00:00
Debug: Service process started.
Debug: Connected via Named Pipe ProtectedPrefix\Administrators\gsudo_4B66ADB72EB4FAECCD55F24FDFFF0ED1A190F775E230E330C00313D5F39CA336.
Debug: Creating target process: C:\WINDOWS\system32\cmd.exe /v:on /s /c ""C:\Program Files\WindowsApps\Microsoft.PowerShell_7.4.1.0_x64__8wekyb3d8bbwe\pwsh.exe" -NoLogo -NoProfile -encodedCommand IABHAGUAdAAtAE4AZQB0AEkAUABBAGQAZAByAGUAcwBzACAA -inputFormat xml -outputFormat text"
Debug: Process token successfully substituted.
ParentContainsErrorRecordException:
Line |
 622 |      $__cmdletization_objectModelWrapper.ProcessRecord($__cmdletizatio …
     |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "ProcessRecord" with "1" argument(s): "The type initializer for 'Microsoft.Management.Infrastructure.Native.ApplicationMethods' threw an exception."
Debug: Process exited with code 1

image

Context:

cloud-yu commented 4 months ago

it only occurs with pwsh is installed by msstore works fine when reinstall it by .msi package

gerardog commented 4 months ago

I also have Pwsh 7.4.1 installed via msstore (at C:\Program Files\WindowsApps\Microsoft.PowerShell_7.4.1.0_x64__8wekyb3d8bbwe\pwsh.exe), and it is working fine for me...

image

I need additional information to detect where the problem is, for example, what happenes if you use the msstore Pwsh and run: pwsh {get-NetIPAddress}

Thank you

cloud-yu commented 4 months ago

Sorry, I can't reproduce this problem after reinstall win11, looks like this is a win11 problem. I think I should close this issue

gerardog commented 4 months ago

No problem, others finding this error message while using gsudo can +1 here. Thank you @cloud-yu