How to query OneDrive sync status for a given file
Asked Answered
G

2

18

Now that Microsoft have reinstated OneDrive in the file system in Windows 10 (and assuming they don't drop it again in 6 months time), I'm looking for how to determine the sync status of an arbitrary file.

There are at least five different states shown in Explorer (this is just what I've observed, there may be others):

  • Available when online Available when online
  • Available on this device Available on this device
  • Always available on this device Always available on this device
  • Syncing / downloading Syncing / downloading
  • Error Error

The first two states, for a file, can be determined using the FILE_ATTRIBUTE_OFFLINE attribute.

It seems that the "Always available" state can be determined for a file using a new, undocumented file attribute 0x00080000.

Determining these states for folders, and the syncing and error states for both files and folders, however remains a mystery.

My first thought was using the property system (IPropertyStore), but the following four property keys all failed to help:

  • PKEY_OfflineAvailability returns VT_EMPTY
  • PKEY_OfflineStatus returns VT_EMPTY
  • PKEY_FilePlaceholderStatus returns an undocumented value (0xe) but it doesn't change when the status does
  • PKEY_FileOfflineAvailabilityStatus returns VT_EMPTY

I have a feeling this is going to turn out to be just another undocumented Microsoft API but I thought I'd ask to see if anyone has any suggestions.

Geometrid answered 23/10, 2017 at 15:5 Comment(10)
My experiences tend to show that it's the undocumented PKEY_StorageProviderState ({e77e90df-6271-4f5b-834f-2dd1f245dda4} 3) that seems to contain some (undocumented also) enum value.There is a mention of this property in ShObjIdl.idl but what I see doesn't seem to correspond to the values of SYNC_ENGINE_STATE_FLAGS. Note the latest SDK has also a new cfapi.h ("cloud file" API) that could be interesting too...Hafiz
There is Determining availability of Microsoft OneDrive files, but all the APIs used require an app identity. The reason for this is not immediately apparent to me.Libau
and BTW, 0x80000 is FILE_ATTRIBUTE_PINNED (from winnt.h, appeared in Creators Update SDK 10.0.15063.0) whatever that could mean...Hafiz
@SimonMourier Ah ha, interesting. I don't have that in my Win10 SDK, will have to check why the latest version hasn't installed. I found this from your mention of cfapi.h so I suspect this is the right track to take. Thanks!Geometrid
@SimonMourier I've been digging into the cloud API (badly documented, as usual for Microsoft) but no joy - it doesn't seem designed to provide this sort of higher-level information.Geometrid
IMHO, I think they have plan to document only the WinRT/UWP/whatever side of these: learn.microsoft.com/en-us/uwp/api/windows.storage.provider not the old Win32 side wich does live. There is this new wide (and still fuzzy) concept of "[Cloud] Storage Provider". I guess the relevant values are located in windows.storage.provider.idl. PKEY_StorageProviderState could map to one of the enums in that idl. Maybe FileUpdateStatus learn.microsoft.com/en-us/uwp/api/… still the names don't match, and that doesn't smell 100% right...Hafiz
Oh... rereading your question... you ask what are the values for PKEY_FilePlaceholderStatus. Well, this is somewhat documented as being PLACEHOLDER_STATES: msdn.microsoft.com/en-us/library/windows/desktop/dn457657.aspx but as you say, it doesn't change. But, it seems it corresponds to the values I observe for the undocumented PKEY_StorageProviderState for OneDrive (OneDrive is definitely a storage provider, DropBox seems to be another)Hafiz
@SimonMourier So typical of Microsoft to ignore the desktop completely these days. I think you're right though - PKEY_StorageProviderState looks to be the one to go for. Now to work out what the values mean!Geometrid
Note that PKEY_StorageProviderState was broken in Windows 10 1903 (and still not fixed in 1909). It returns 4 ("uploading") in any app besides Explorer.Geometrid
Hey @JonathanPotter, were you able to solve your problem? If so, could you please share some code? I need the same thing.Softboiled
U
3

I tried reverse-engineering it on Windows 11 22H2 and this is what I found:

Two properties appear different when a file is still syncing:

  • System.FilePlaceholderStatus is 15 when done, and 7 when still syncing. E.g. 0x8 bit set == done syncing.
  • System.SyncTransferStatusFlags is 1 when syncing and is 0 or null otherwise.
Undoing answered 12/9, 2023 at 18:47 Comment(0)
V
1

As a minor contribute I can add that while developing an UWP app I had the challenge to retrieve the status. What I found is: 14: available locally; 15: always available locally (still have to understand th difference with 14) 8: available on cloud.

Velvetvelveteen answered 18/7, 2024 at 17:18 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.