Example #1
0
        /// <summary>
        /// Gets a single user from the Backup Store and returns the information in a UserRow object.
        /// </summary>
        /// <param name="TemplateRow">A template UserRow to fill the values of.</param>
        /// <param name="ID">Backup Store ID to retrieve.</param>
        /// <returns>UserRow object.</returns>
        static public Task <UserRow> GetUserFromStore(UserRow TemplateRow, string ID)
        {
            Dictionary <ULColumnType, string> Files = new Dictionary <ULColumnType, string>
            {
                { ULColumnType.NTAccount, "ntaccount" },
                { ULColumnType.SourceComputer, "source" },
                { ULColumnType.DestinationComputer, "destination" },
                { ULColumnType.ImportedBy, "importedby" },
                { ULColumnType.ImportedOn, "importedon" },
                { ULColumnType.ExportedBy, "exportedby" },
                { ULColumnType.ExportedOn, "exportedon" }
            };

            return(Task.Run(() =>
            {
                try
                {
                    string StoreItemPath = Path.Combine(Config.Settings["MigrationStorePath"], ID);
                    UserRow row = new UserRow(TemplateRow);
                    DirectoryInfo info = new DirectoryInfo(StoreItemPath);
                    row[ULColumnType.Tag] = info.Name;
                    string DataFilePath = Path.Combine(StoreItemPath, "data");
                    if (row.ContainsKey(ULColumnType.Size))
                    {
                        row[ULColumnType.Size] = new FileInfo(DataFilePath).Length.ToString();
                    }
                    foreach (KeyValuePair <ULColumnType, string> file in Files)
                    {
                        string filePath = Path.Combine(StoreItemPath, file.Value);
                        if (row.ContainsKey(file.Key) && File.Exists(filePath))
                        {
                            row[file.Key] = File.ReadAllText(filePath);
                        }
                    }
                    return row;
                }
                catch (Exception e)
                {
                    Logger.Exception(e, "Failed to get user from store, ID: " + ID);
                    return null;
                }
            }));
        }
Example #2
0
        /// <summary>
        /// The entry point for the UserProperties form.
        /// </summary>
        /// <param name="Template">Template user rows to generate the "Properties" column.</param>
        /// <param name="Row">The rows with data to fill in the "Values" column.</param>
        public UserProperties(UserRow Template, UserRow Row)
        {
            InitializeComponent();
            Icon = Properties.Resources.user_ico;
            btnOK.SetSystemIcon(Properties.Resources.check_ico);
            foreach (KeyValuePair <ULColumnType, string> property in Row)
            {
                string name  = "";
                string value = ULControl.ConvertColumnValue(property);
                if (property.Key == ULColumnType.NTAccount)
                {
                    Text = value;
                }
                if (Template.ContainsKey(property.Key))
                {
                    name = Template[property.Key];
                }
                else
                {
                    name = property.Key.ToString();
                }
                ListViewItem lvProperty = lvProperties.Items.Add(name);
                lvProperty.SubItems.Add(value);
            }
            lvProperties.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
            lvProperties.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
            int headWidth = 0;

            foreach (ColumnHeader colHeader in lvProperties.Columns)
            {
                headWidth += colHeader.Width;
            }
            Width  = headWidth + 20;
            Height = (17 * Row.Count) + 95;
            CenterToParent();
        }
Example #3
0
 /// <summary>
 /// Retrieves a single users properties from a Host.
 /// </summary>
 /// <param name="TemplateRow">A template row to fill in with information from the host.</param>
 /// <param name="Host">A host computer to get the information from.</param>
 /// <param name="SID">An SID (Security Identifier) of the user profile on the host.</param>
 /// <returns>Filled in UserRow.</returns>
 public static Task <UserRow> GetUserFromHost(UserRow TemplateRow, string Host, string SID)
 {
     return(Task.Run(async() =>
     {
         UserRow row = new UserRow(TemplateRow);
         RegistryKey remoteReg = null;
         if (IsHostThisMachine(Host))
         {
             remoteReg = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Default);
         }
         else
         {
             remoteReg = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, Host);
         }
         string user = GetUserByIdentity(SID);
         Logger.Verbose("Found: " + user);
         bool setting;
         if (bool.TryParse(Config.Settings["HideBuiltInAccounts"], out setting) && setting && (user.Contains("NT AUTHORITY") || user.Contains("NT SERVICE")))
         {
             Logger.Verbose("Skipped: " + SID + ": " + user + ".");
             return null;
         }
         if (bool.TryParse(Config.Settings["HideUnknownSIDs"], out setting) && setting && SID == user)
         {
             Logger.Verbose("Skipped unknown SID: " + SID + ".");
             return null;
         }
         row[ULColumnType.Tag] = SID;
         if (row.ContainsKey(ULColumnType.NTAccount))
         {
             row[ULColumnType.NTAccount] = user;
         }
         if (row.ContainsKey(ULColumnType.LastModified) || row.ContainsKey(ULColumnType.Size) || row.ContainsKey(ULColumnType.FirstCreated))
         {
             RegistryKey profileReg = remoteReg.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\" + SID, false);
             string profilePathReg = (string)profileReg.GetValue("ProfileImagePath");
             if (profilePathReg == null)
             {
                 Logger.Verbose("Skipped SID with no profile directory: " + SID + ".");
                 return null;
             }
             string profilePath = profilePathReg.Replace(@"C:\", GetBestPathToC(Host));
             if (row.ContainsKey(ULColumnType.Size))
             {
                 Logger.Information("Calculating profile size for: " + user + "...");
                 double size = await FileOperations.GetFolderSize(profilePath);
                 row[ULColumnType.Size] = size.ToString();
             }
             if (row.ContainsKey(ULColumnType.FirstCreated))
             {
                 row[ULColumnType.FirstCreated] = Directory.GetCreationTime(profilePath).ToFileTime().ToString();
             }
             if (row.ContainsKey(ULColumnType.LastModified))
             {
                 row[ULColumnType.LastModified] = File.GetLastWriteTime(Path.Combine(profilePath, "NTUSER.DAT")).ToFileTime().ToString();
             }
         }
         remoteReg.Close();
         return row;
     }));
 }