private static List <ServerComponentStates.ItemEntry> GetLocalStates(string targetServerFqdn, string component)
        {
            string name = string.Format("{0}\\{1}", "SOFTWARE\\Microsoft\\ExchangeServer\\v15\\ServerComponentStates", component);
            List <ServerComponentStates.ItemEntry> result;

            using (RegistryKey localMachineKey = ServerComponentStates.GetLocalMachineKey(targetServerFqdn))
            {
                using (RegistryKey registryKey = localMachineKey.OpenSubKey(name))
                {
                    List <ServerComponentStates.ItemEntry> list = new List <ServerComponentStates.ItemEntry>();
                    if (registryKey == null)
                    {
                        result = list;
                    }
                    else
                    {
                        foreach (string text in registryKey.GetValueNames())
                        {
                            object       value = registryKey.GetValue(text);
                            ServiceState state;
                            DateTime     timestamp;
                            if (ServerComponentStates.IsValidName(text) && registryKey.GetValueKind(text) == RegistryValueKind.String && ServerComponentStates.TryParseLocalStateString(value as string, out state, out timestamp))
                            {
                                list.Add(new ServerComponentStates.ItemEntry(component, text, state, timestamp));
                            }
                        }
                        result = list;
                    }
                }
            }
            return(result);
        }
        public static void UpdateLocalState(string targetServerFqdn, string requester, string component, ServiceState state)
        {
            if (!ServerComponentStates.IsValidName(component))
            {
                throw new ArgumentException(DirectoryStrings.ComponentNameInvalid);
            }
            if (!ServerComponentStates.IsValidName(requester))
            {
                throw new ArgumentException(DirectoryStrings.RequesterNameInvalid);
            }
            string subkey = string.Format("{0}\\{1}", "SOFTWARE\\Microsoft\\ExchangeServer\\v15\\ServerComponentStates", component);

            using (RegistryKey localMachineKey = ServerComponentStates.GetLocalMachineKey(targetServerFqdn))
            {
                using (RegistryKey registryKey = localMachineKey.CreateSubKey(subkey))
                {
                    ServerComponentStates.LogTransition(component, requester, state);
                    registryKey.SetValue(requester, ServerComponentStates.FormLocalString(state, DateTime.UtcNow));
                }
            }
        }