コード例 #1
0
        private void SetUserList()
        {
            ManagementObjectSearcher   usersSearcher = new ManagementObjectSearcher(@"SELECT * FROM Win32_UserAccount");
            ManagementObjectCollection users         = usersSearcher.Get();

            var rawAllUsers    = users.Cast <ManagementObject>();
            var rawActiveUsers = rawAllUsers.Where(u =>
            {
                return((bool)u["LocalAccount"] == true && (bool)u["Disabled"] == false && (bool)u["Lockout"] == false && int.Parse(u["SIDType"].ToString()) == 1 && u["Name"].ToString() != "HomeGroupUser$");
            });

            var allUsers    = (from item in rawAllUsers select item["Name"].ToString()).ToList();
            var activeUsers = (from item in rawActiveUsers select item["Name"].ToString()).ToList();

            AllUsernameList.AddRange(allUsers);

            if (activeUsers.Count < 2)
            {
                return;
            }

            UsernameList.Clear();
            PickUsername = "";

            var username = Environment.UserName;

            foreach (var activeUser in activeUsers)
            {
                if (activeUser != username)
                {
                    UsernameList.Add(activeUser);
                }
            }
        }
コード例 #2
0
        private void Finish()
        {
            if (string.IsNullOrEmpty(MFPath))
            {
                UtilHelper.ShowAlertDialog(new Model.AlertDialogInterfaceModel {
                    Content = "未选择美服游戏路径"
                });
                return;
            }

            if (!UserType)
            {
                if (string.IsNullOrEmpty(PickUsername) || PickUsername.Equals(pickUserPlaceholder))
                {
                    UtilHelper.ShowAlertDialog(new Model.AlertDialogInterfaceModel {
                        Content = "请选择用户或新建用户"
                    });
                    return;
                }
            }
            else
            {
                if (string.IsNullOrEmpty(NewUsername))
                {
                    UtilHelper.ShowAlertDialog(new Model.AlertDialogInterfaceModel {
                        Content = "请输入新用户名"
                    });
                    return;
                }

                if (AllUsernameList.IndexOf(NewUsername) != -1)
                {
                    UtilHelper.ShowAlertDialog(new Model.AlertDialogInterfaceModel {
                        Content = "用户名已存在,或者是系统保留用户名"
                    });
                    return;
                }
            }

            if (string.IsNullOrEmpty(Password))
            {
                UtilHelper.ShowAlertDialog(new Model.AlertDialogInterfaceModel {
                    Content = "请输入密码"
                });
                return;
            }

            if (!UserType)
            {
                if (UtilHelper.VerifySystemUser(PickUsername, Password))
                {
                    try
                    {
                        UtilHelper.CheckSystemUserFolderAndCreate(PickUsername, Password);
                    }
                    catch (Exception e)
                    {
                        UtilHelper.ShowAlertDialog(new Model.AlertDialogInterfaceModel {
                            Content = "生成用户文件夹失败:\r\n" + e.Message
                        });
                        return;
                    }

                    _ConfigManager.SaveMFUser(PickUsername, Password);
                }
                else
                {
                    UtilHelper.ShowAlertDialog(new Model.AlertDialogInterfaceModel {
                        Content = "密码不正确"
                    });
                    return;
                }
            }
            else
            {
                try
                {
                    UtilHelper.CreateSystemUser(NewUsername, Password);
                }
                catch (Exception e)
                {
                    UtilHelper.ShowAlertDialog(new Model.AlertDialogInterfaceModel {
                        Content = "创建新用户失败:\r\n" + e.Message
                    });
                    return;
                }

                try
                {
                    UtilHelper.CheckSystemUserFolderAndCreate(NewUsername, Password);
                }
                catch (Exception e)
                {
                    UtilHelper.ShowAlertDialog(new Model.AlertDialogInterfaceModel {
                        Content = "生成用户文件夹失败:\r\n" + e.Message
                    });
                    return;
                }

                _ConfigManager.SaveMFUser(NewUsername, Password);
            }

            _ConfigManager.SaveGamePath(MFPath, "MF");
            DialogCallback?.Invoke(true);
            ((ICommand)ControlCommands.Close).Execute(null);
        }