See other methods. Create a Windows account locally using C# (DirectoryServices)
/blog/?id=917
Under WinForm, the program can be written as: (Tested and needs to be run as Administrator)
using System;
namespace eg
{
class test
{
static void Main()
{
//Declare a program information class
Info = new ();
//Set external program name
= "";
//Set the startup parameters (command line parameters) of the external program to
= " user abc /add";
//Set the working directory of the external program as D:\
= "D:\\";
//Declare a program class
Proc ;
try
{
//
//Start external programs
//
Proc = (Info);
}
catch(.Win32Exception e)
{
("The system cannot find the specified program file.\r{0}", e);
return;
}
}
}
}
Note: The ASPNET account belongs to the Users group. The Users group does not have full control over the computer, so some commands involved in system management cannot be used; as for why it is not visible in the process, it is because the statement is run on the command line. If you want to see the effect, you can only view it under CMD: net user
Add an administrator:
("","/c net user admin 123456 /add");
("","/c net localgroup administrators admin /add");
Modify admin's password to 250:
("","/c net user admin 250 ");
Delete the administrator:
("","/c net user admin /del");
It can be fully operated under CMD, and command line tools such as ("net user ...");
net user
Used to add/create/change user accounts
grammar:
net user <username> [password or *] [/add] [options] [/domain]
net user <username] /delete /domain
username account name
password Assign or change password
* password hint
/domain Execute in a domain
/add Create an account
/delete Delete an account
/active:[yes or no] Activate or stop an account
/comment:"<text>" Add a descriptive note
/ nnn is the system encoding. 0 is the system default value
/expires:<date or never> Account expiration time. Format: month, day, year or day, month, year (the format is determined by the country code)
/fullname:"<name>" Full name of the account
/homedir:<path> User home directory path
/passwordchg:[yes or no] Set whether the user can change the password
/passwordreq:[yes or no] Set whether the user needs a password
/profilepath:<path> Set the environment file path
/scriptpath:<path> Login script path
/times:<times or all> The number of hours a user can log in
/usercomment:"<text>" Account description information
/workstations:<machine names> The username that allows login. * Indicates all users
/blog/?id=917
Under WinForm, the program can be written as: (Tested and needs to be run as Administrator)
using System;
namespace eg
{
class test
{
static void Main()
{
//Declare a program information class
Info = new ();
//Set external program name
= "";
//Set the startup parameters (command line parameters) of the external program to
= " user abc /add";
//Set the working directory of the external program as D:\
= "D:\\";
//Declare a program class
Proc ;
try
{
//
//Start external programs
//
Proc = (Info);
}
catch(.Win32Exception e)
{
("The system cannot find the specified program file.\r{0}", e);
return;
}
}
}
}
Note: The ASPNET account belongs to the Users group. The Users group does not have full control over the computer, so some commands involved in system management cannot be used; as for why it is not visible in the process, it is because the statement is run on the command line. If you want to see the effect, you can only view it under CMD: net user
Add an administrator:
("","/c net user admin 123456 /add");
("","/c net localgroup administrators admin /add");
Modify admin's password to 250:
("","/c net user admin 250 ");
Delete the administrator:
("","/c net user admin /del");
It can be fully operated under CMD, and command line tools such as ("net user ...");
net user
Used to add/create/change user accounts
grammar:
net user <username> [password or *] [/add] [options] [/domain]
net user <username] /delete /domain
username account name
password Assign or change password
* password hint
/domain Execute in a domain
/add Create an account
/delete Delete an account
/active:[yes or no] Activate or stop an account
/comment:"<text>" Add a descriptive note
/ nnn is the system encoding. 0 is the system default value
/expires:<date or never> Account expiration time. Format: month, day, year or day, month, year (the format is determined by the country code)
/fullname:"<name>" Full name of the account
/homedir:<path> User home directory path
/passwordchg:[yes or no] Set whether the user can change the password
/passwordreq:[yes or no] Set whether the user needs a password
/profilepath:<path> Set the environment file path
/scriptpath:<path> Login script path
/times:<times or all> The number of hours a user can log in
/usercomment:"<text>" Account description information
/workstations:<machine names> The username that allows login. * Indicates all users