Create a Windows local user account using C #

xiaoxiao2021-03-06  37

Using The Windows Net Command, It's Easy To Create Local Windows User Accounts. The Syntax for the Net Command IS:

Net user [username] [password] / add

The Following C # function takes in three parameters - Username, Password and home Directory.

Using system.diagnostics;

Public void CreatelocalUser (String ", string passir)

{

IF (! Directory.exists (Homedir))

Directory.createDirectory (Homedir);

PROCESS myproc = new process ();

Myproc.startinfo.workingdirectory = "C: / WinNT / 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 = @ " username @" " password @" / add / active: yes "

@ "/ Expires: never / fullname:" username @ "/ homedir:" ""

Homedir @ "" / passwordchg: no / passwordreq: yes ";

Myproc.start ();

Myproc.waitforexit ();

MyProc.Close ();

}

IT Assumes a few settings for the user and create a local the settings to anything you want. Try "net help user" in your dos prompt for what Each of the switches mean / do.

转载请注明原文地址:https://www.9cbs.com/read-61845.html

New Post(0)