Skip to content

Fix ParentContainsErrorRecordException if a Windows limited user resets Winget sources #2150

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

Merged
merged 3 commits into from
Apr 26, 2024

Conversation

pomodori92
Copy link
Contributor

  • I have read the contributing guidelines and I agree with the Code of Conduct
  • Have you checked that there aren't other open pull requests for the same changes?
  • Have you tested that the committed code can be executed without errors?
  • This PR is not composed of garbage changes used to farm GitHub activity to enter potential Crypto AirDrops.
    Any user suspected of farming GitHub activity with crypto purposes will get banned. Submitting broken code wastes the time of the contributors, who have to spend their free time reviewing, fixing, and testing code that does not even compile, breaks other features, or does not introduce any useful changes. Thank you for your understanding

I have Microsoft Windows 10 with two user accounts: the first one is administrator and the second oneis limited.

With the limited user account, when I try to reset the winget sources, the script arrives at the line 11:
powershell -file "%~dp0\delete_winget_databases.ps1"

and it got me this error:

Failed to load file C:\Program Files\WingetUI\Assets\Utilities\delete_winget_databases.ps1. The file C:\Program Files\WingetUI\Assets\Utilities\delete_winget_databases.ps1 s not digitally signed. The script can't run on the current system. For more information about running scripts and setting policies execution policies, see about_Execution_Policies at https://go.microsoft.com/fwlink/?LinkID=135170.
    + CategoryInfo          : Protection error: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnauthorizedAccess

Adding the following line before line 11, that changes PowerShell Execution Politcy, solves the error:
powershell Set-ExecutionPolicy Unrestricted

And adding the following line after line 11 the Execution Policy default value is restored:
powershell Set-ExecutionPolicy Default

Fix: when a Microsoft Windows limited user executes it and the script arrives at the line 11:
powershell -file "%~dp0\delete_winget_databases.ps1"

it got this error:
Failed to load file C:\Program Files\WingetUI\Assets\Utilities\delete_winget_databases.ps1. The file
C:\Program Files\WingetUI\Assets\Utilities\delete_winget_databases.ps1 s not digitally signed. The script can't
run on the current system. For more information about running scripts and setting policies
execution policies, see about_Execution_Policies at https://go.microsoft.com/fwlink/?LinkID=135170.
    + CategoryInfo          : Protection error: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnauthorizedAccess

Adding the following line before line 11 solves the error:
powershell Set-ExecutionPolicy Bypass
marticliment
marticliment previously approved these changes Apr 19, 2024
@marticliment
Copy link
Owner

Wouldn't it be better to bypass the execution policy when calling the script? Because this could reset what a user could have set before...

@pomodori92
Copy link
Contributor Author

pomodori92 commented Apr 19, 2024

You can change the following line:
powershell Set-ExecutionPolicy Unrestricted

with this following line:
powershell Set-ExecutionPolicy Bypass

Anyway I prefer to restore Execution Policy to the default value with this line after the powershell script execution:
powershell Set-ExecutionPolicy Default

At this link there are all Execution Policies described: about_Execution_Policies.

marticliment
marticliment previously approved these changes Apr 26, 2024
@marticliment marticliment merged commit 64d3e20 into marticliment:main Apr 26, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants