I could have spent a ton of time tracking down the key on Google, but, I prefer to use Sysinternals tools instead. First, I fired up Process Monitor with the Control Panel open. Once Process Monitor was capturing I simply clicked the Include Process from Window icon
and highlighted the inner window of the Control Panel. After making my change I saw a few entries pop up in Process Explorer. Flipping back I saw the path I needed to focus on.
Using this path I simply opened regedit, tweaked the values to test.
Once I was sure this was my key, I wrote the following function in PowerShell to handle it for my script. Note that this is profile dependent (HKCU).
function Set-ControlPanelViewToSmallIcons
{
Write-Output "$(Write-TimeStamp): Attempting to set Control Panel View to `"Small Icons`"."
if((Get-ItemProperty -Path "HKCU:SoftwareMicrosoftWindowsCurrentVersionExplorerControlPanel" -Name AllItemsIconView).AllItemsIconView -eq 1)
{
Write-Output "$(Write-TimeStamp): Control Panel View already set to `"Small Icons`"."
}
else
{
Write-Output "$(Write-TimeStamp): Control Panel View not set to `"Small Icons`". Attempting to set now."
Set-ItemProperty -Path "HKCU:SoftwareMicrosoftWindowsCurrentVersionExplorerControlPanel" -Name AllItemsIconView -Value 1
Write-Output "$(Write-TimeStamp): Validating Control Panel View has been set to `"Small Icons`"."
if((Get-ItemProperty -Path "HKCU:SoftwareMicrosoftWindowsCurrentVersionExplorerControlPanel" -Name AllItemsIconView).AllItemsIconView -eq 1)
{
Write-Output "$(Write-TimeStamp): Control Panel View has been updated to `"Small Icons`"."
}
else
{
Write-Error "$(Write-Error): Control Panel View was not set to `"Small Icons`". Cancelling processing."
}
}
}
In the example above, $(Write-Error) is just a wrapper function for Get-Date -Format yyyyMMddHHmmss.
Together Sysinternals tools and PowerShell can go a long way. This is a very simple illustration of an other wise tedious and time-consuming process reduced to about a 3 minute task thanks to the right tools.
0 comments:
Post a Comment