使用c#.net在我的域中添加网络中的所有计算机 [英] Add All Computers in network in my domain using c#.net
问题描述
您好
我是这类问题的初学者,我只是想添加我的所有计算机而不是它可能在网络中,我可以访问我的域名,,我已经做了一些事情,但它只是为了更改我的本地名称,电脑名称 现在我只想添加它2我的域名,它可以是任何我无法触及的电脑
I am beginner to this kind of problem ,, i just wanna add all my computer rather it may be in network ,,accessible by me to my domain ,, i hve done something with that , but it's only for changing name of my local, pc name now i just wanna add it 2 my domain,, it can be any pc that is under my reach
string args4,args2;
string compPath =" Win32_ComputerSystem.Name ='" + System.Environment.MachineName +"'" ;;
ManagementObject comp = new ManagementObject(new ManagementPath(compPath));
ManagementBaseObject inputArgs = comp.GetMethodParameters(" Rename");
inputArgs [" Name"] =" ComputerName"; // this 可以是我想要的名字 ManagementBaseObject outParams = comp.InvokeMethod(" Rename",inputArgs,null);
uint ret =(uint)(outParams.Properties [" ReturnValue"]。Value);
if(ret!= 0)
{
           回复于(" Sucess");
        }
       否则
        {
           回复于("不");
        }
string args4, args2;
string compPath= "Win32_ComputerSystem.Name='" + System.Environment.MachineName +"'";
ManagementObject comp = new ManagementObject(new ManagementPath(compPath));
ManagementBaseObject inputArgs = comp.GetMethodParameters("Rename");
inputArgs["Name"] = "ComputerName";// this can be ny name i want
ManagementBaseObject outParams = comp.InvokeMethod("Rename", inputArgs, null);
uint ret = (uint)(outParams.Properties["ReturnValue"].Value);
if (ret != 0)
{
Response.Write("Sucess");
}
else
{
Response.Write("not");
}
推荐答案
ManagementObjectCollection Comps = new ManagementObjectCollection();
  ; ManagementObject comp = new ManagementObject();
ManagementClass clsComps = new ManagementClass(" Win32_ComputerSystem"); Label1.Text = comp.SystemProperties [" name"]。Value.ToString();
Comps = clsComps.GetInstances();
// object result = o.InvokeMethod(" JoinDomain or workgroup",methodArgs);
object [] methodArgs = {" domain"," password"," username"," oupath",1}; UInt32 retVal = Convert.ToUInt32(comp.InvokeMethod(" JoinDomainOrWorkgroup",methodArgs));
        int retval2 = Convert.ToInt32(retVal);
if(retval2 == 0)
{
          Response.Write("欢迎使用域名"); }
     否则 {
      回复于("错误");
        }
       }
ManagementObjectCollection Comps = new ManagementObjectCollection();
ManagementObject comp= new ManagementObject();
ManagementClass clsComps = new ManagementClass("Win32_ComputerSystem");
Label1.Text = comp.SystemProperties["name"].Value.ToString();
Comps = clsComps.GetInstances();
//object result = o.InvokeMethod("JoinDomain or workgroup", methodArgs);
object[] methodArgs = {"domain","password","username","oupath",1};
UInt32 retVal = Convert.ToUInt32(comp.InvokeMethod("JoinDomainOrWorkgroup",methodArgs));
int retval2 = Convert.ToInt32(retVal);
if(retval2 == 0)
{
Response.Write("Welcome to the domain");
}
else
{
Response.Write("Error");
}
}
我收到以下错误"类型'System.Management.ManagementObjectCollection'没有定义构造函数"
I am getting the following error "The type 'System.Management.ManagementObjectCollection' has no constructors defined"
可能的原因是什么以及以下
what is the possible reason and solution for the following
这篇关于使用c#.net在我的域中添加网络中的所有计算机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!