public override IEnumerable <CommandDTOBase?> Execute(string[] args) { // Get all of the user SIDs (so will cover all users if run as an admin or has access to other user's reg keys) var SIDs = ThisRunTime.GetUserSIDs(); foreach (var sid in SIDs) { if (!sid.StartsWith("S-1-5") || sid.EndsWith("_Classes")) // Disregard anything that isn't a user { continue; } OneDriveSyncProvider o = new OneDriveSyncProvider(); // Now get each of the IDs (they aren't GUIDs but are an identity value for the specific library to sync) var subKeys = ThisRunTime.GetSubkeyNames(RegistryHive.Users, $"{sid}\\Software\\SyncEngines\\Providers\\OneDrive"); if (subKeys == null) { continue; } // Now go through each of them, get the metadata and stick it in the 'provider' dict. It'll get cross referenced later. foreach (string rname in subKeys) { Dictionary <string, string> provider = new Dictionary <string, string>(); foreach (string x in new List <string> { "LibraryType", "LastModifiedTime", "MountPoint", "UrlNamespace" }) { var result = ThisRunTime.GetStringValue(RegistryHive.Users, $"{sid}\\Software\\SyncEngines\\Providers\\OneDrive\\{rname}", x); if (!string.IsNullOrEmpty(result)) { provider[x] = result; } } o.mpList[rname] = provider; } var odAccounts = ThisRunTime.GetSubkeyNames(RegistryHive.Users, $"{sid}\\Software\\Microsoft\\OneDrive\\Accounts"); if (odAccounts == null) { continue; } foreach (string acc in odAccounts) { Boolean business = false; Dictionary <string, string> account = new Dictionary <string, string>(); foreach (string x in new List <string> { "DisplayName", "Business", "ServiceEndpointUri", "SPOResourceId", "UserEmail", "UserFolder", "UserName", "WebServiceUrl" }) { var result = ThisRunTime.GetStringValue(RegistryHive.Users, $"{sid}\\Software\\Microsoft\\OneDrive\\Accounts\\{acc}", x); if (!string.IsNullOrEmpty(result)) { account[x] = result; } if (x == "Business") { business = (String.Compare(result, "1") == 0) ? true : false; } } var odMountPoints = ThisRunTime.GetValues(RegistryHive.Users, $"{sid}\\Software\\Microsoft\\OneDrive\\Accounts\\{acc}\\ScopeIdToMountPointPathCache"); List <string> ScopeIds = new List <string>(); if (business == true) { foreach (var mp in odMountPoints) { ScopeIds.Add(mp.Key); } } else { ScopeIds.Add(acc); // If its a personal account, OneDrive adds it as 'Personal' or the name of the account, not by the ScopeId itself. You can only have one personal account. } o.AcctoMPMapping[acc] = ScopeIds; o.oneDriveList[acc] = account; o.usedScopeIDs.AddRange(ScopeIds); } yield return(new CloudSyncProviderDTO( sid, o )); } }
public CloudSyncProviderDTO(string sid, OneDriveSyncProvider odsp) { Sid = sid; Odsp = odsp; }