Exemplo n.º 1
0
        internal static bool Exist(string name)
        {
            var command = $"Get-Service {name} -ErrorAction Ignore";

            var result = ScriptInvoker.InvokeScript(command);

            return(result.Any());
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
 public static void CreateUser(string userName, string userPassword)
 {
     ScriptInvoker.InvokeScript($"net user {userName} {userPassword} /add");
 }
Exemplo n.º 4
0
 public static void DeleteUser(string userName)
 {
     ScriptInvoker.InvokeScript($"net user {userName} /delete");
 }
Exemplo n.º 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));
        }