用C#在本地创建一个Windows帐户(DOS命令)
用C#在本地创建一个Windows帐户(DOS命令)
发布时间:2016-12-28 来源:查字典编辑
摘要:其它方法见.用C#在本地创建一个Windows帐户(DirectoryServices)http://yaosansi.com/blog/a...

其它方法见.用C#在本地创建一个Windows帐户(DirectoryServices)

http://yaosansi.com/blog/article.asp?id=917

在WinForm下该程序可写成:(已测试通过,需要以Administrator身份运行)

usingSystem;

namespaceeg

{

classtest

{

staticvoidMain()

{

//声明一个程序信息类

System.Diagnostics.ProcessStartInfoInfo=newSystem.Diagnostics.ProcessStartInfo();

//设置外部程序名

Info.FileName="net.exe";

//设置外部程序的启动参数(命令行参数)为test.txt

Info.Arguments="userabc/add";

//设置外部程序工作目录为D:

Info.WorkingDirectory="D:";

//声明一个程序类

System.Diagnostics.ProcessProc;

try

{

//

//启动外部程序

//

Proc=System.Diagnostics.Process.Start(Info);

}

catch(System.ComponentModel.Win32Exceptione)

{

Console.WriteLine("系统找不到指定的程序文件。r{0}",e);

return;

}

}

}

}

注:ASPNET帐户隶属于Users组,Users组对计算机没有完全控制权,涉及到系统管理的一些命令就无法使用了;至于为什么在进程中看不到是因为该条语句是以命令行运行的,要看效果的话只能在CMD下:netuser查看

添加管理员:

System.Diagnostics.Process.Start("CMD.exe","/cnetuseradmin123456/add");

System.Diagnostics.Process.Start("CMD.exe","/cnetlocalgroupadministratorsadmin/add");

修改admin的密码为250:

System.Diagnostics.Process.Start("CMD.exe","/cnetuseradmin250");

删除管理员:

System.Diagnostics.Process.Start("CMD.exe","/cnetuseradmin/del");

在CMD下就可以完全操作了,可以直接调用命令行工具如System.Diagnostics.Process.Start("netuser...");

netuser用法

用于增加/创建/改动用户帐户

语法:

netuser<username>[passwordor*][/add][options][/domain]

netuser<username]/delete/domain

username帐号名

password分配或改变密码

*密码提示

/domain在一个域中执行

/add创建一个帐号

/delete删除一个帐户

/active:[yesorno]激活或停止一个帐号

/comment:"<text>"加入描述性说明

/counterycode.nnnnnn是系统编码.0为系统缺省值

/expires:<dateornever>帐号到期时间.格式:月,日,年或日,月,年(格式由国家代码决定)

/fullname:"<name>"帐号全名

/homedir:<path>用户主目录路径

/passwordchg:[yesorno]设置用户能否更改密码

/passwordreq:[yesorno]设置用户是否需要密码

/profilepath:<path>设置环境文件路径

/scriptpath:<path>登录脚本路径

/times:<timesorall>用户可以登录的小时数

/usercomment:"<text>"帐号说明信息

/workstations:<machinenames>允许登录的用户名.*表示所有用户

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新C#教程学习
热门C#教程学习
编程开发子分类