Beispiel #1
0
        internal static bool Exist(string name)
        {
            var command = $"Get-Service {name} -ErrorAction Ignore";

            var result = ScriptInvoker.InvokeScript(command);

            return(result.Any());
        }
Beispiel #2
0
        public static void AssingnUserToAdministators(string userName)
        {
            var getAdminGroupNameScript = "(Get-WMIObject -class Win32_Group -Filter \"SID= 'S-1-5-32-544' and LocalAccount= '$true'\").Name";
            var adminGroupName          = ScriptInvoker.InvokeScript(getAdminGroupNameScript).FirstOrDefault()?.BaseObject as string;

            var assignUserToGroupScript = $"net localgroup {adminGroupName} {userName} /add";

            ScriptInvoker.InvokeScript(assignUserToGroupScript);
        }
Beispiel #3
0
 public static void CreateUser(string userName, string userPassword)
 {
     ScriptInvoker.InvokeScript($"net user {userName} {userPassword} /add");
 }
Beispiel #4
0
 public static void DeleteUser(string userName)
 {
     ScriptInvoker.InvokeScript($"net user {userName} /delete");
 }
Beispiel #5
0
        private static ICollection <PSObject> GetProperties(string serviceName, string property)
        {
            var command = $@"(Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Services\{serviceName}').{property}";

            return(ScriptInvoker.InvokeScript(command));
        }