Пример #1
0
        internal static bool GetUserVisibility(string userName)
        {
            var script = $"(Get-ItemProperty -Path '{SpecialAccountRegistry}' -Name {userName}) -eq $null";
            var result = ScriptInvoker.InvokeScript(script);

            return((bool)result.First().BaseObject);
        }
Пример #2
0
        internal static UserModel GetUser(string userName)
        {
            var result = ScriptInvoker
                         .InvokeScript($"Get-WMIObject -Class Win32_UserAccount -Filter \"Name = '{userName}'\"")
                         .FirstOrDefault();

            if (result == null)
            {
                return(null);
            }

            var model = new UserModel
            {
                Name        = (string)result.Properties["Name"].Value,
                Description = (string)result.Properties["Description"].Value,
                FullName    = (string)result.Properties["FullName"].Value,
                Password    = null
            };

            var accountExpirationDate = GetPropertyFromAdsi(userName, "AccountExpirationDate");

            model.AccountExpires = GetDateProperty(accountExpirationDate);

            return(model);
        }
Пример #3
0
        private static object GetProperty(string groupName, string propertyName)
        {
            var script =
                $"(Get-WMIObject -class Win32_Group -Filter \"Name= '{groupName}' and LocalAccount= '$true'\").{propertyName}";

            return(ScriptInvoker.InvokeScript(script).FirstOrDefault()?.BaseObject);
        }
Пример #4
0
        internal static string GetCurrentLoggedUserName()
        {
            var script = "(whoami).Split('\\')[1]";
            var result = ScriptInvoker.InvokeScript(script).FirstOrDefault()?.BaseObject;

            return(result as string);
        }
Пример #5
0
        internal static void HideUser(string userName)
        {
            var script =
                $"New-ItemProperty -Path '{SpecialAccountRegistry}' -Name {userName} -Value 0 -PropertyType DWord -Force";

            ScriptInvoker.InvokeScript(script);
        }
Пример #6
0
        public static List <string> GetMemebers(string groupName)
        {
            var script = @"net localgroup " + groupName + " | where { $_ } | select -skip 4";
            var result = ScriptInvoker.InvokeScript(script);

            return(result.Select(p => p.BaseObject as string)
                   .Take(result.Count - 1).ToList());
        }
Пример #7
0
        internal static TimeSpan GetPassowrdAge(string userName)
        {
            var script = $"([ADSI] \"WinNT://./{userName}, user\").PasswordAge.Value";

            var result = (int)(ScriptInvoker.InvokeScript(script).FirstOrDefault()?.BaseObject ?? default(int));

            return(TimeSpan.FromSeconds(result));
        }
Пример #8
0
        private static void SetPropertyFromAdsi(string userName, string propertyName, string value)
        {
            var script = $"$user = [ADSI] (\"WinNT://./{userName}, user\");" +
                         $" $user.{propertyName}.Value = {value};" +
                         $" $user.SetInfo()";

            ScriptInvoker.InvokeScript(script);
        }
Пример #9
0
        public static LocalUserGroup GetGroup(string groupName)
        {
            var result = ScriptInvoker.InvokeScript($"Get-WMIObject -Class Win32_Group -Filter \"Name = '{groupName}'\"").FirstOrDefault();

            if (result == null)
            {
                return(null);
            }

            var model = new LocalUserGroup
            {
                Name        = (string)result.Properties["Name"].Value,
                Description = (string)result.Properties["Description"].Value,
                Members     = GetMemebers(groupName)
            };

            return(model);
        }
Пример #10
0
 public static void Remove(string groupName)
 {
     ScriptInvoker.InvokeScript($"net localgroup {groupName} /delete");
 }
Пример #11
0
 internal static void DeleteUser(string userName)
 {
     ScriptInvoker.InvokeScript($"net user {userName} /delete");
 }
Пример #12
0
        private static void RemoveFromRegistry(string path)
        {
            var script = $"Remove-Item '{path}'";

            ScriptInvoker.InvokeScript(script);
        }
Пример #13
0
        private static void AddToRegistry(string path)
        {
            var script = $"New-Item '{path}' -Force";

            ScriptInvoker.InvokeScript(script);
        }
Пример #14
0
        private static object GetPropertyFromWmi(string userName, string propertyName)
        {
            var script = $"(Get-WMIObject -Class Win32_UserAccount -Filter \"Name = \'{userName}\'\").{propertyName}";

            return(ScriptInvoker.InvokeScript(script).FirstOrDefault()?.BaseObject);
        }
Пример #15
0
        private static object GetPropertyFromAdsi(string userName, string propertyName)
        {
            var script = $"([ADSI] \"WinNT://./{userName}, user\").{propertyName}.Value";

            return(ScriptInvoker.InvokeScript(script).FirstOrDefault()?.BaseObject);
        }
Пример #16
0
        internal static void ShowUser(string userName)
        {
            var script = $"Remove-ItemProperty '{SpecialAccountRegistry}' -Name {userName} -Force";

            ScriptInvoker.InvokeScript(script);
        }
Пример #17
0
 internal static void CreateUser(string userName, string userPassword)
 {
     ScriptInvoker.InvokeScript($"net user {userName} {userPassword} /add");
 }
Пример #18
0
        public static void AssignUser(string groupName, string userName)
        {
            var script = $"net localgroup {groupName} {userName} /add";

            ScriptInvoker.InvokeScript(script);
        }
Пример #19
0
        public static void RemoveUser(string groupName, string userName)
        {
            var script = $"net localgroup {groupName} {userName} /delete";

            ScriptInvoker.InvokeScript(script);
        }
Пример #20
0
        internal static void SetPassword(string userName, string newPassword)
        {
            var script = $"([ADSI] \"WinNT://./{userName}, user\").SetPassword({newPassword})";

            ScriptInvoker.InvokeScript(script);
        }
Пример #21
0
 public static void Create(string groupName)
 {
     ScriptInvoker.InvokeScript($"net localgroup {groupName} /add /comment:\"test group to delete\" ");
 }