我想通过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!");
} 同时,希望各位大大帮我提供一份将本计算机加入域的代码.谢谢
我得到一份更改本计算机名称的代码,但是提示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!");
} 同时,希望各位大大帮我提供一份将本计算机加入域的代码.谢谢
解决方案 »
- winform打印问题?如何去掉"正在打印"提示窗口,直接打印
- 设置资源字典出错了。
- 应用程序中ico图标资源的问题
- 如何获取winform中正在运行的Timer计时器
- 难道.net制作网页在后台能不能对<embed >进行编程访问?
- 从数据库中读取控件的属性,然后对控件赋属性,这步如何做?
- 定义一个函数,返回值为整数,参数为一个数组,
- 关于Null Object模式
- 请问当listview没有焦点时,通过HideSelection可以使选中的项仍突出显示,我想问一下,如何改变突出显示的颜色。
- textBox1_TextChanged事件调用keychar怎么报错,如何修改
- 在线急等
- 高手帮忙看看,这个输出来应该是多少啊?
__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);
//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 仍然提示有问题。怎么回事啊。
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("修改成功");
}
}
}修改本地计算机名称,已经写出来了。哪位给我提供个把本地计算机加入域的代码啊?