The BagMRU
key indexes saved views, associating a fully-qualified path with a numbered property bag, with the view settings saved in a subkey of the adjacent Bags
key.
But the numbering/nnaming of the keys is not fixed, but rather dependent on when a folder is first viewed. If a user hasn't viewd the folder in Explorer, there won't be a bag. In short, this is not the way to attempt this.
To manipulate the saved view for a folder, the folder must be open in Explorer to access and modify the view using the various com objects available via shell.application
. In PowerShell, create an instance using:
$Shell = New-Object -ComObject shell.application
Use the Windows
method to retrieve open Explorer windows. An EXplorer window has the following properties:
Application : System.__ComObject
Parent : System.__ComObject
Container :
Document : System.__ComObject
TopLevelContainer : True
Type :
Left : 0
Top : 0
Width : 1462
Height : 625
LocationName : Windows (C:)
LocationURL : file:///C:/
Busy : False
Name : File Explorer
HWND : 78776658
FullName : C:\WINDOWS\explorer.exe
Path : C:\WINDOWS\
Visible : True
StatusBar : False
StatusText :
ToolBar : 1
MenuBar : False
FullScreen : False
ReadyState : 4
Offline : False
Silent : False
RegisterAsBrowser : False
RegisterAsDropTarget : True
TheaterMode : False
AddressBar : True
Resizable : True
The Document
property is itself a com object. It's through this object that we can get
/set
cetain aspects of the folder view.
Application : System.__ComObject
Parent :
Folder : System.__ComObject
FocusedItem : System.__ComObject
Script :
ViewOptions : 139
CurrentViewMode : 8
GroupBy : System.Null
FolderFlags : 1090519041
SortColumns : prop:System.ItemNameDisplay;
IconSize : 32
CurrentVIewMode
and IconSize
are the values to modify. Use values from the Mode
column of this table:
Name LVM Mode Vid IconSize
---- --- ---- --- --------
Details 1 4 {137E7700-3573-11CF-AE69-08002B2E1262} 16
Tiles 2 6 {65F125E5-7BE1-4810-BA9D-D271C8432CE3} 48
SmIcons 3 1 {089000C0-3573-11CF-AE69-08002B2E1262} 16..31
Icons(M-XL) 3 1 {0057D0E0-3573-11CF-AE69-08002B2E1262} 33..256
List 4 3 {0E1FA5E0-3573-11CF-AE69-08002B2E1262} 16
Content 5 8 {30C2C434-0889-4C8D-985D-A9F71830B0A9} 32
Here's some sample code:
$Shell = New-Object -ComObject shell.application
Function WaitFor-NewWindow ( $CurrentCount )
{
Do { Sleep -m 50 } Until ( $Shell.Windows().Count -gt $CurrentCount )
}
Function Get-TargetWindow ( $Path )
{
$OpenWindows = @( $Shell.Windows() )
If ( $TargetWindow = $OpenWindows | ? { $_.Document.Folder.Self.Path -like $Path } )
{
$TargetWindow
}
Else
{
$Shell.Open( $Target )
WaitFor-NewWindow $OpenWindows.Count
@( $Shell.Windows() ) | ? HWND -notIn $OpenWindows.HWND
}
}
$Target = 'C:\'
$TargetWindow = Get-TargetWindow $Target
$TargetWindow.Document.CurrentViewMode = 1
$TargetWindow.Document.IconSize = 96
$TargetWindow.Quit()