实现效果:
知识运用:
API函数SetComputerName
实现代码:
private void Form1_Load(object sender, EventArgs e) { label1.Text="原计算机名: "+Environment.MachineName; } [DllImport("kernel32.dll")] public static extern int SetComputerName(string IpComputerName); private void button1_Click(object sender, EventArgs e) { if (textBox1.Text == "") MessageBox.Show("内容不能为空"); else { SetComputerName(textBox1.Text); MessageBox.Show("修改成功 重新启动后生效"); } }