用c#如何更改计算机用户名

如果可以的话,密码顺带下!我主要的就是更改计算机用户名!等待....(可以运行的话,100%追加分的!!)
具体点的,要详细的注释。谢谢了!!

1. 使用命名空间:
using System.Runtime.InteropServices;
2. 在类中声明:
 [DllImport("kernel32.dll", EntryPoint = "SetComputerNameEx")]
 public static extern int apiSetComputerNameEx(int type, string lpComputerName);
3. 在实现代码处调用:
apiSetComputerNameEx(5, "TestComputerNameModification");
样例:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace ConsoleApplication1
{
    class Program
    {
        [DllImport("kernel32.dll", EntryPoint = "SetComputerNameEx")]
        public static extern int apiSetComputerNameEx(int type, string lpComputerName); 
        static void Main(string[] args)
        {
            int rtn = apiSetComputerNameEx(5, "TestComputerNameModification");
            System.Console.WriteLine("Computer name set result="+rtn);
        }
    }

4. 修改计算机名,需要重启操作系统才能生效。

温馨提示:内容为网友见解,仅供参考
第1个回答  2010-03-23
Process.Start("cmd.exe","/c net user bb bbb /add "); //新增用户名为bb密码为bbb的用户
Process.Start("cmd.exe","/c net localgroup administrators bb /add "); //将用户bb加入管理员组
Process.Start("cmd.exe","/c net user aa /del "); //删掉aa用户

先增加你想要的再删掉你不想要的账号,达到修改的目的
第2个回答  2010-03-23
声明:
//api SetComputerNameEx
//iType说明:
//typedef enum _COMPUTER_NAME_FORMAT
// {
// ComputerNameNetBIOS,
// ComputerNameDnsHostname,
// ComputerNameDnsDomain,
// ComputerNameDnsFullyQualified,
// ComputerNamePhysicalNetBIOS,
// ComputerNamePhysicalDnsHostname,
// ComputerNamePhysicalDnsDomain,
// ComputerNamePhysicalDnsFullyQualified,
// ComputerNameMax
// } COMPUTER_NAME_FORMAT ;
//
//lpComputerName说明: 计算机名称
[DllImport(“kernel32.dll“,EntryPoint=“SetComputerNameEx“)] public static extern int apiSetComputerNameEx(int iType,string lpComputerName);

设定计算机名称:
// set computer Name
int i = apiSetComputerNameEx(5,”RobertTest!”);
if (i == 0)
{
MessageBox.Show(“Modify Computer Name failed,Please try again!“);
}
else
{
MessageBox.Show(“Computer Name is Modified, Please Restart Computer Now!“);
}本回答被提问者采纳
第3个回答  2010-03-23
yrtyrtyrtytryrtyrty
相似回答