Writing properties #9 - Summary

Coding to the Windows SDK 
Reading properties #7 - Summary

Writing properties #1 - Simple beginnings
Writing properties #2 - Filetype support?
Writing properties #3 - Which properties are writable?
Writing properties #4 - Which properties are writable?
Writing properties #5 - Property lists
Writing properties #6 - GPS_READWRITE omits read-only data sources
The deal with IPropertyStoreCapabilities
Writing properties #8 - Canonical Values
Gotcha: You must release property stores quickly


Writing properties is very simple at the core: you just call SetValue() and then Commit(). But then there are a bunch of details surrounding this task that make it a little more complicated. To close this topic, I want to give one more tip:

The best way to determine if the file/filesystem/filetype itself is writable is to simply call IShellItem2::GetPropertyStore(GPS_READWRITE). This performs the necessary ACL checks, attribute checks, etc. The only downside is that the return value is non-actionable. If you want to display a more specifical error message or offer corrective options, you'll have to program those yourself.

Thus, a property editing user interface will typically do the following:

  1. Test writability by opening the file with GPS_READWRITE and then release that interface
  2. Reopen the file with GPS_DEFAULT
  3. Use a property list to populate the UI
  4. Test writability using IPropertyDescription::GetTypeFlags
  5. Test writability using IPropertyStoreCapabilities::IsPropertyWritable
  6. Release the read-only property store

Then to save changes, it...

  1. Opens the file with GPS_READWRITE
  2. Calls IPropertyStore::SetValue for each change
  3. Calls IPropertyStore::Commit to save the changes
  4. Releases the read-write store

-Ben Karas

ps. There is an even simpler way to write properties using IFileOperation. I'll have to revisit that another time.