Skip to content

Do not fail uninstall when PowerShell profile cleanup fails#74

Open
a-rookie-of-C-language wants to merge 1 commit into
microsoft:mainfrom
a-rookie-of-C-language:fix/uninstall-pwsh-optional
Open

Do not fail uninstall when PowerShell profile cleanup fails#74
a-rookie-of-C-language wants to merge 1 commit into
microsoft:mainfrom
a-rookie-of-C-language:fix/uninstall-pwsh-optional

Conversation

@a-rookie-of-C-language
Copy link
Copy Markdown

Summary

close #73
Make uninstall robust to PowerShell profile cleanup failures.

PowerShell profile cleanup is now skipped when pwsh.exe is unavailable or
unsupported, and cleanup failures during uninstall are logged instead of aborting
the uninstall process.

Install-time PowerShell integration behavior remains strict when integration is
selected.

Validation

  • git diff --check
  • Inno Setup compilation not run locally: ISCC.exe is unavailable

Copy link
Copy Markdown
Contributor

@caomengxuan666 caomengxuan666 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems correct.Have you ever tested it at the same env?Or run a smoke test on it?

@a-rookie-of-C-language
Copy link
Copy Markdown
Author

是的,我做过了一次测试,日志显示
Skipping PowerShell profile cleanup because pwsh.exe is unavailable or unsupported
之后显示
Uninstallation process succeeded.
并且注册表卸载项也没了,Machine PATH 里也没有临时安装路径残留。
至少它在我本地机器上运行得很好

Comment thread coreutils.iss
Comment on lines +252 to +257
if IgnoreFailure then
begin
Log('Skipping PowerShell profile update because pwsh.exe could not be executed');
Exit;
end;
RaiseException('Failed to execute pwsh.exe');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error cannot occur, because on installation we first check if pwsh.exe is installed and works. RunPwshScript is not called otherwise.

@lhecker
Copy link
Copy Markdown
Member

lhecker commented Jun 8, 2026

@a-rookie-of-C-language Could you explain what this PR improves over #40?
My understanding is that #40 alone has already fixed your issue #73. You say that #40 has multiple flaws, but they cannot possibly occur due to the conditions in coreutils.iss. I have tested this locally by replacing "pwsh.exe" with "does_not_exist.exe" in coreutils.iss.

@a-rookie-of-C-language
Copy link
Copy Markdown
Author

a-rookie-of-C-language commented Jun 8, 2026

当本机没有 pwsh.exe 时,#40 已经修复了这个问题 ,不会阻断卸载。
但是当pwsh.exe存在时,但是返回非0
例如:

@a-rookie-of-C-language
Copy link
Copy Markdown
Author

a-rookie-of-C-language commented Jun 8, 2026

我使用git worktree复现了 #40 无法解决的内容
image
我破坏了pwsh-install.ps1让pwsh.exe返回非0
#40 的log:

2026-06-09 03:39:19.235   Cleaning up any residual temporary files from previous Uninstall runs.
2026-06-09 03:39:19.236   Cleanup finished (5 directories found, 5 directories checked, 0 files deleted).
2026-06-09 03:39:19.237   Created protected temporary directory: D:\caches\temp\is-FV6ZK1MCZW.tmp
2026-06-09 03:39:19.239   -- DLL function import --
2026-06-09 03:39:19.239   Function and DLL name: CreateHardLinkW@kernel32.dll
2026-06-09 03:39:19.239   Importing the DLL function. Dest DLL name: kernel32.dll
2026-06-09 03:39:19.239   Successfully imported the DLL function. Delay loaded? No
2026-06-09 03:39:20.710   CurUninstallStepChanged raised an exception (fatal).
2026-06-09 03:39:20.710   Exception message:
2026-06-09 03:39:20.710   Message box (OK):
                          Runtime error (at 23:989):
                          
                          Failed to update PowerShell profiles: �[31;1mWrite-Error: �[31;1mdamaged pwsh-install.ps1 from full installer test�[0m.
2026-06-09 03:39:28.133   User chose OK.
2026-06-09 03:39:28.151   Log closed.

#74 的日志为

2026-06-09 03:40:23.673   Deleting file: D:\caches\temp\coreutils-pr74-fulltest\install-pr74\unins000.dat
2026-06-09 03:40:23.673   Failed to delete the file; it may be in use (32).
2026-06-09 03:40:23.673   Deleting file: D:\caches\temp\coreutils-pr74-fulltest\install-pr74\unins000.exe
2026-06-09 03:40:23.673   Failed to delete the file; it may be in use (5).
2026-06-09 03:40:23.673   Deleting directory: D:\caches\temp\coreutils-pr74-fulltest\install-pr74
2026-06-09 03:40:23.673   Failed to delete directory (145). Will retry later.
2026-06-09 03:40:23.738   Deleting Uninstall data files.
2026-06-09 03:40:23.738   Creating "_unins-done.tmp" file.
2026-06-09 03:40:24.259   Deleting directory: D:\caches\temp\coreutils-pr74-fulltest\install-pr74
2026-06-09 03:40:24.259   Uninstallation process succeeded.
2026-06-09 03:40:24.259   Removed all? Yes
2026-06-09 03:40:24.259   Need to restart Windows? No
2026-06-09 03:40:24.680   Log closed.

@a-rookie-of-C-language
Copy link
Copy Markdown
Author

a-rookie-of-C-language commented Jun 8, 2026

这类损坏不一定是用户手动造成的,也可能是磁盘错误、杀毒软件隔离、不完整的上一次安装等导致的,属于卸载程序应当处理的边缘情况,而不是前提条件不满足,当然我上面为了方便测试是手动损坏的pwsh-install.ps1

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.

uninstall coreutils will Failed to update PowerShell profiles in pwsh.exe loss

3 participants