Closed matthijsr closed 1 year ago
Since you have this running, would you mind testing the following?
using var item = new ShellItem(path);
using var propertyDescriptions = item.GetPropertyDescriptionList();
propertyDescriptions.ReadOnly = false;
foreach (var description in ...
I'm assuming you mean:
using var item = new ShellItem(path);
using var propertyDescriptions = item.GetPropertyDescriptionList();
item.Properties.ReadOnly = false;
foreach (var description in ...
Since there's no ReadOnly property on PropertyDescriptionList*.
This throws:
System.Runtime.InteropServices.COMException : Access Denied. (0x80030005 (STG_E_ACCESSDENIED))
Stack Trace:
at Vanara.PInvoke.Shell32.IShellItem2.GetPropertyStore(GETPROPERTYSTOREFLAGS flags, Guid& riid)
at Vanara.Windows.Shell.ShellItemPropertyStore.GetIPropertyStore()
at Vanara.Windows.Shell.ReadOnlyPropertyStore.Run[T](Func`2 action)
at Vanara.Windows.Shell.ReadOnlyPropertyStore.get_Keys()
at Vanara.Windows.Shell.ReadOnlyPropertyStore.ContainsKey(PROPERTYKEY key)
For that same file.
*(That's on me, really. Sorry for the slightly wonky example using keys from PropertyDescriptionList to access the ShellItemPropertyStore - I was working backwards from some other attempts at resolving the issue when I wrote that example.)
Some other things I've tried:
PROPERTYKEY.System.PropList
. None worked.I made a change to ShellItemPropertyStore
so it defaults to GPS_BESTEFFORT
instead of GPS_DEFAULT
and it now works with your first example w/o exceptions.
Describe the bug and how to reproduce
Sometimes, attempting to retrieve a property from a ShellItem will result in a System.Runtime.InteropServices.COMException. (Using
ShellItem.Properties.GetValueOrDefault
)I've noticed this happening with
.exe
files most often (e.g., reading the items in a WinPython or Adobe Acrobat Reader install directory), though it's not consistent and I haven't been able to find the common thread between them.No current configuration of
ShellItemPropertyStore
seems to resolve the issue. However, creating a read-only PropertyStore with theGPS_BESTEFFORT
flag (instead of the currentGPS_DEFAULT
) does work.What code is involved
https://github.com/dahall/Vanara/blob/master/Windows.Shell.Common/ShellProperties/ShellItemPropertyStore.cs
For comparison, the following code results in a COMException* when tested against certain files (for instance,
AdobeGenuineSlimInstaller.exe
from an Acrobat Reader DC installation):Whereas this does not:
*The specific exception is:
Expected behavior
The intention of this code was to replace a PowerShell script which performed
ShellFolder.GetDetailsOf
calls. GetDetailsOf would consistently succeed, whereShellItem.Properties
would throw an exception.I would prefer
ShellItemPropertyStore
to safely retrieve properties, or at least provide a means of setting theGPS_BESTEFFORT
flag without also settingReadOnly
to false.