/// <summary> /// Retrieves users from the Backup Store in a UserRows object. (UserRows are based off of the ULControl.CurrentHeaderRow property.) /// </summary> /// <returns>A UserRow object.</returns> static public Task <UserRows> GetUsersFromStore() { return(Task.Run(async() => { try { string StorePath = Config.Settings["MigrationStorePath"]; Logger.Information("Listing users from store: " + StorePath + "..."); UserRows rows = new UserRows(); int count = 0; DirectoryInfo[] directories = new DirectoryInfo(StorePath).GetDirectories(); foreach (DirectoryInfo directory in directories) { UserRow row = await GetUserFromStore(ULControl.CurrentHeaderRow, directory.Name); if (row == null) { Logger.Warning("Skipping ID: " + directory.Name); continue; } rows.Add(row); Logger.UpdateProgress((int)(((float)++count / directories.Length) * 100)); Logger.Verbose("Found: " + row[ULColumnType.NTAccount]); } Logger.Success("Users listed successfully."); return rows; } catch (Exception e) { Logger.Exception(e, "Failed to list users from store."); return null; } })); }
/// <summary> /// Retrieves users' properties from host based on the ULControl.CurrentHeaderRow property. /// </summary> /// <param name="Host">Host to get information from.</param> /// <returns>UserRows.</returns> public static Task <UserRows> GetUsersFromHost(string Host) { return(Task.Run(async() => { try { UserRows rows = new UserRows(); RegistryKey remoteReg = null; if (IsHostThisMachine(Host)) { remoteReg = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Default); } else { remoteReg = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, Host); } RegistryKey profileList = remoteReg.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList", false); Logger.Information("Getting list of users on: " + Host + "..."); GetLocalUsersSIDsFromHost(Host); string[] SIDs = profileList.GetSubKeyNames(); int count = 0; foreach (string SID in SIDs) { if (Main.Canceled) { break; } UserRow row = await GetUserFromHost(ULControl.CurrentHeaderRow, Host, SID); Logger.UpdateProgress((int)(((float)++count / SIDs.Length) * 100)); if (row != null) { rows.Add(row); } } remoteReg.Close(); if (Main.Canceled) { Logger.Warning("Listing users was canceled."); return null; } Logger.Success("Users listed successfully."); return rows; } catch (System.Security.SecurityException e) { Logger.Exception(e, "Failed to get a list of users. Please make sure the user \"" + Environment.UserDomainName + "\\" + Environment.UserName + "\" is an administrator on the host: " + Host); return null; } catch (Exception e) { Logger.Exception(e, "Failed to get a list of users. Please make sure that the specified host is valid and online, also make sure the \"Remote Registry\" service is enabled and running on the specified host: " + Host); return null; } })); }