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

Avoid error when installing packages in headless mode #1266

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/common.vm/common.vm.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
<metadata>
<id>common.vm</id>
<version>0.0.0.20250124</version>
<version>0.0.0.20250204</version>
Copy link
Member

Choose a reason for hiding this comment

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

I have just merged a PR that updated this package, so there is now a merge conflict here. @thack1 can you please fix it?

<description>Common libraries for VM-packages</description>
<authors>Mandiant</authors>
</metadata>
Expand Down
2 changes: 1 addition & 1 deletion packages/common.vm/tools/vm.common/vm.common.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1534,7 +1534,7 @@ public class Shell {
$SHCNF_IDLIST = 0
[void][Shell]::SHChangeNotify($SHCNE_ASSOCCHANGED, $SHCNF_IDLIST, [IntPtr]::Zero, [IntPtr]::Zero)
# Refresh the Taskbar
Stop-Process -Name explorer -Force # This restarts the explorer process so that the new taskbar is displayed.
Stop-Process -Name explorer -Force -ErrorAction SilentlyContinue # This restarts the explorer process so that the new taskbar is displayed.
Copy link
Member

Choose a reason for hiding this comment

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

I think using -ErrorAction Continue would still prevent this from failing (fixing the issue you are encoutering) and display the error, which I think it is in general useful.

Suggested change
Stop-Process -Name explorer -Force -ErrorAction SilentlyContinue # This restarts the explorer process so that the new taskbar is displayed.
Stop-Process -Name explorer -Force -ErrorAction Continue # This restarts the explorer process so that the new taskbar is displayed.

Copy link
Member

Choose a reason for hiding this comment

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

[nitpick] I think it would be a good idea to document why the -ErrorAction Continue is needed (to avoid we forget about the reason and delete it). The current comments are a bit confusing (as we have two comments saying the same, one more detailed). Proposal:

# Restart the explorer process to refresh the taskbar.
# Use '-ErrorAction Continue' to avoid failing the package installation if it fails,
# for example if there is no desktop session (as in this case explorer.exe is not running)
 Stop-Process -Name explorer -Force -ErrorAction Continue

} catch {
VM-Write-Log-Exception $_
}
Expand Down
Loading