Skip to content

Commit

Permalink
[VM-Clean-Up] Sort Desktop icons by type
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Ana06 committed Feb 28, 2024
1 parent 2b5d0b1 commit 721e51a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
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.20240123</version>
<version>0.0.0.20240220</version>
<description>Common libraries for VM-packages</description>
<authors>Mandiant</authors>
</metadata>
Expand Down
12 changes: 12 additions & 0 deletions packages/common.vm/tools/vm.common/vm.common.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,16 @@ public class Shell {
}
}

# Sort Desktop icons by item type using WScript.Shell to replicate the manual steps
function VM-Sort-Desktop-Icons {
VM-Write-Log "INFO" "Sorting Desktop icons"
(New-Object -ComObject Shell.Application).toggleDesktop();
Start-Sleep -Milliseconds 100;
$objShell = New-Object -ComObject WScript.Shell;
$objShell.SendKeys("^{ }+{F10}oi");
Start-Sleep -Milliseconds 100;
}

# Usage example:
# VM-Remove-DesktopFiles -excludeFolders "Labs", "Demos" -excludeFiles "MICROSOFT Windows 10 License Terms.txt", "Labs.zip"
# The function is run against both the Current User and 'Public' desktops due to some cases where desktop icons showing on
Expand Down Expand Up @@ -1327,6 +1337,8 @@ function VM-Remove-DesktopFiles {
}
}
}

VM-Sort-Desktop-Icons
}

function VM-Clear-TempAndCache {
Expand Down

0 comments on commit 721e51a

Please sign in to comment.