0%

C# 设置计算机名称

设置修改当前计算机名称

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using Microsoft.VisualBasic.Devices;
using System.Runtime.InteropServices;

namespace ModifyComputerName
{
public partial class Frm_Main : Form
{
public Frm_Main()
{
InitializeComponent();
}

[DllImport("kernel32.dll")]
private static extern int SetComputerName(string ipComputerName);//重写API函数

private void Frm_Main_Load(object sender, EventArgs e)
{
Computer computer = new Computer();//创建计算机对象
textBox1.Text = computer.Name;//显示计算机名称

SetComputerName(textBox2.Text);//修改计算机名称
}
}
}
觉得文章有用?请我喝杯咖啡~