Управление учетными записами windows - C#
Формулировка задачи:
Подскажите как
1 Создать пользователя (администратор или не админ)
2 удалить пользователя
3 Отключить пользователя
4 Включить пользователя
Решение задачи: «Управление учетными записами windows»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace usercreater
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void CreateLocalUser(string username, string password, string homedir)
{
if (!Directory.Exists(homedir))
Directory.CreateDirectory(homedir);
Process MyProc = new Process();
MyProc.StartInfo.WorkingDirectory = "C:\\Windows\\SYSTEM32";
MyProc.StartInfo.FileName = "net.exe";
MyProc.StartInfo.UseShellExecute = false;
MyProc.StartInfo.RedirectStandardError = true;
MyProc.StartInfo.RedirectStandardInput = true;
MyProc.StartInfo.RedirectStandardOutput = true;
MyProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
MyProc.StartInfo.Arguments = @"user " + username + @" " + password + @" /ADD /ACTIVE:YES " +
@"/EXPIRES:NEVER /FULLNAME:"+ username + @" /HOMEDIR:""" +
homedir + @""" /PASSWORDCHG:NO /PASSWORDREQ:YES" ;
MyProc.Start();
MyProc.WaitForExit();
MyProc.Close();
}
public void Createadmin(string username)
{
Process Myadm = new Process();
Myadm.StartInfo.FileName = "net.exe";
Myadm.StartInfo.WorkingDirectory = "C:\\Windows\\SYSTEM32";
Myadm.StartInfo.UseShellExecute = false;
Myadm.StartInfo.RedirectStandardError = true;
Myadm.StartInfo.RedirectStandardInput = true;
Myadm.StartInfo.RedirectStandardOutput = true;
Myadm.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
Myadm.StartInfo.Arguments =@"localgroup Администраторы " + username+ @" /ADD";
Myadm.Start();
Myadm.WaitForExit();
Myadm.Close();
}
public void deleteLocalUser(string username, string homedir)
{
Process MyProc = new Process();
MyProc.StartInfo.WorkingDirectory = "C:\\Windows\\SYSTEM32";
MyProc.StartInfo.FileName = "net.exe";
MyProc.StartInfo.UseShellExecute = false;
MyProc.StartInfo.RedirectStandardError = true;
MyProc.StartInfo.RedirectStandardInput = true;
MyProc.StartInfo.RedirectStandardOutput = true;
MyProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
MyProc.StartInfo.Arguments = @" user " + username + @" /DELETE";
MyProc.Start();
MyProc.WaitForExit();
MyProc.Close();
}