3

is it possible to change the explorer view of specific folder C:\ to large icons using VBA ? I have used this program RegistryChangesView to capture changes to windows registry , and I got this data:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\BagMRU\0\0]
"MRUListEx"=hex(3):00,00,00,00,01,00,00,00,02,00,00,00,FF,FF,FF,FF 

I applied later but it has no effect at all (Folder view still list).
I think it can be done by Windows API (I am not familiar with it).
In advance,any help are welcome.

enter image description here

1 Answer 1

4

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.

BagMRU key

enter image description here

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()
4
  • Thanks for your effort , But is it possible to change by VBA or even script rather than registry
    – Waleed
    Commented Jan 3, 2022 at 7:47
  • Yes, it's possible. Your posting of the BagMRU led me to assume you were wanting to modify the view via a registry edit. That assumption infuenced the emphasis of my answer on the shortcomings of such a route. I will edit my post with a PowerShell example as I've forgetten vbs/vba syntax. But the view modification is accomplished via the shell.application and related com objects, so translation shouldn't be much of an issue. Commented Jan 3, 2022 at 9:07
  • I am sorry for late reply as I did not got any notification that you updated your initial answer.
    – Waleed
    Commented Mar 29, 2022 at 7:52
  • 1
    No worries. Waking up to more points is a nice surprise... :D Commented Mar 29, 2022 at 15:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .