我想通过C#来实现将本机加入域和修改本机的名称
我得到一份更改本计算机名称的代码,但是提示INT(红色部分)有问题.如下:
  //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!");         
        }         同时,希望各位大大帮我提供一份将本计算机加入域的代码.谢谢

解决方案 »

  1.   

    应该是public static extern  int apiSetComputerNameEx(int iType,string  lpComputerName);        这个红色的int出错了。BOOL WINAPI SetComputerNameEx(
      __in          COMPUTER_NAME_FORMAT NameType,
      __in          LPCTSTR lpBuffer
    );第一参数应该是COMPUTER_NAME_FORMAT 试一试
    public enum COMPUTER_NAME_FORMAT {    
                     ComputerNameNetBIOS,        
                  ComputerNameDnsHostname,        
                  ComputerNameDnsDomain,        
                  ComputerNameDnsFullyQualified,        
                  ComputerNamePhysicalNetBIOS,        
                  ComputerNamePhysicalDnsHostname,        
                  ComputerNamePhysicalDnsDomain,        
                  ComputerNamePhysicalDnsFullyQualified,   
    }[DllImport("kernel32.dll",EntryPoint="SetComputerNameEx")]      
    public static extern  int apiSetComputerNameEx(COMPUTER_NAME_FORMAT  iType,string  lpComputerName);        
      

  2.   

        //api      SetComputerNameEx        
            //iType說明:        
            //typedef      enum      _COMPUTER_NAME_FORMAT            
            //      {        
            //      ComputerNameNetBIOS,        
            //      ComputerNameDnsHostname,        
            //      ComputerNameDnsDomain,        
            //      ComputerNameDnsFullyQualified,        
            //      ComputerNamePhysicalNetBIOS,        
            //      ComputerNamePhysicalDnsHostname,        
            //      ComputerNamePhysicalDnsDomain,        
            //      ComputerNamePhysicalDnsFullyQualified,        
            //      ComputerNameMax        
            //      }      COMPUTER_NAME_FORMAT      ;        
            //        
            //lpComputerName說明:      計算機名稱        
            public enum COMPUTER_NAME_FORMAT {    
                    ComputerNameNetBIOS,        
                  ComputerNameDnsHostname,        
                  ComputerNameDnsDomain,        
                  ComputerNameDnsFullyQualified,        
                  ComputerNamePhysicalNetBIOS,        
                  ComputerNamePhysicalDnsHostname,        
                  ComputerNamePhysicalDnsDomain,        
                  ComputerNamePhysicalDnsFullyQualified,  
    } [DllImport("kernel32.dll",EntryPoint="SetComputerNameEx")]      
    public static extern  int apiSetComputerNameEx(COMPUTER_NAME_FORMAT  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!");        
            }        int 仍然提示有问题。怎么回事啊。
      

  3.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Microsoft.Win32;
    using System.Net;namespace ap2
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                label1.Text = Dns.GetHostName();
            }        private void button1_Click(object sender, EventArgs e)
            {
                RegistryKey myRKCN = Registry.LocalMachine.OpenSubKey("SYSTEM\\ControlSet001\\Services\\Tcpip\\Parameters",true);
                foreach (string site in myRKCN.GetValueNames())
                {
                    if (site == "NV Hostname")
                    {
                        myRKCN.DeleteValue(site, false);
                        myRKCN.SetValue("NV Hostname", this.textBox1.Text);
                    }
                    else
                    {
                        continue;
                    }
                }
                
                MessageBox.Show("修改成功");
            }       
        }
    }修改本地计算机名称,已经写出来了。哪位给我提供个把本地计算机加入域的代码啊?