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

Conversation

thack1
Copy link

@thack1 thack1 commented Feb 4, 2025

VM-Refresh-Desktop tries to restart explorer.exe by using the Stop-Process cmdlet. When installing VM-Packages without a desktop session running (e.g. using ansible) this results in an error, because explorer.exe is not running. This error can be avoided by using ErrorAction SilentlyContinue.

ERROR: Cannot find a process with name "explorer".

Copy link

google-cla bot commented Feb 4, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Member

@Ana06 Ana06 left a comment

Choose a reason for hiding this comment

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

Thank for your contribution @thack1! You need to sign Google CLA, otherwise we are not able to merge your PR.

Please also rebase to fix the version update conflict and see my improvement suggestion. 😉

@@ -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?

@@ -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

@Ana06
Copy link
Member

Ana06 commented Feb 5, 2025

Question (unrelated to this PR but I am curious): @thack1 are you able to install packages like npcap.vm for which we use an AHK installer without a desktop session running? 🤔 also how are you checking if the installation has completed?

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.

2 participants