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

[VM-Clean-Up] Sort Desktop icons by type #909

Merged
merged 1 commit into from
Feb 29, 2024

Conversation

Ana06
Copy link
Member

@Ana06 Ana06 commented Feb 20, 2024

Introduce VM-Sort-Desktop-Icons to sort Desktop icons by type using WScript.Shell to replicate the manual steps using the keyboard. This function is called from VM-Remove-DesktopFiles (called from VM-Clean-Up) to avoid leaving empty spaces after removing Desktop icons.

I would appreciate if someone could also test this code locally. Note you don't need to install the whole FLARe-VM or even the modified package to test the changes. It is enough to copy the functions VM-Remove-DesktopFiles and VM-Remove-DesktopFiles from the modified packages/common.vm/tools/vm.common/vm.common.psm1.

I am using Windows 10 and I am not sure if this code works in Windows 11 and we should prevent from running it in Windows 11 (or add a version for Windows 11). Note this code has to be run manually (by running VM-Clean-Up that the FLARE team is using to automate FLARE-VM builds) and is not part of the installer.

Closes #902

@Ana06 Ana06 added the 💎 enhancement It is working, but it could be better label Feb 20, 2024
@Ana06 Ana06 requested a review from emtuls February 20, 2024 07:29
@Ana06 Ana06 self-assigned this Feb 20, 2024
@emtuls
Copy link
Member

emtuls commented Feb 27, 2024

I tested this and ran into a couple of issues depending on what might have been selected or not in the background before executing the function. Sometimes it didn't work and other times it would open a folder up that was on the desktop.

I believe I found an alternative that seems to work though!

I changed the key strokes line to be $objShell.SendKeys("^a {F5}+{F10}oi");

(New-Object -ComObject Shell.Application).toggleDesktop();
Start-Sleep -Milliseconds 100;
$objShell = New-Object -ComObject WScript.Shell;
$objShell.SendKeys("^{ }+{F10}oi");
Copy link
Member

@emtuls emtuls Feb 27, 2024

Choose a reason for hiding this comment

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

This didn't seem to always work depending on what might have been in focus before executing. I tried it with a folder having been selected before switching to the powershell terminal and executing the command and also with a folder not selected and ran into varying issues.

I was able to modify the key strokes to this and it seems to work more consistently:
^a {F5}+{F10}oi

Copy link
Member Author

@Ana06 Ana06 Feb 28, 2024

Choose a reason for hiding this comment

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

@emtuls doesn't Control+space (^{ }) unselect the folder for you? Can you elaborate on the issues and the purposed solution?

Copy link
Member Author

Choose a reason for hiding this comment

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

I see, if there are several folders selected it does run into issues

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll update the code, good catch @emtuls!

Copy link
Member

@emtuls emtuls left a comment

Choose a reason for hiding this comment

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

Comments explain issue.

@Ana06 Ana06 force-pushed the sort-desktop-icons branch from d81a19a to 721e51a Compare February 28, 2024 15:19
@Ana06 Ana06 requested a review from emtuls February 28, 2024 15:19
Introduce `VM-Sort-Desktop-Icons` to sort Desktop icons by type using
`WScript.Shell` to replicate the manual steps. This function is called
from `VM-Remove-DesktopFiles` (called from `VM-Clean-Up`) to avoid
leaving empty spaces after removing Desktop icons.

Ensure no file(s) or folder(s) is/are selected in `SendKeys` by
selecting all items and unselect them.
@Ana06 Ana06 force-pushed the sort-desktop-icons branch from 721e51a to 81f4020 Compare February 28, 2024 15:21
@Ana06 Ana06 merged commit 047c8ad into mandiant:main Feb 29, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💎 enhancement It is working, but it could be better
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Re-arrange Desktop icons in VM-Clean-Up
2 participants