Đổi tên máy trên bằng c#

0 thích 0 không thích
48 lượt xem
đã hỏi 4 Tháng 5, 2018 trong Lập trình C# bởi ohlalaga (160 điểm)
cho mình hỏi có hàm nào đổi tên máy tính bằng c# không ạ
    

1 câu trả lời

0 thích 0 không thích
đã trả lời 7 Tháng 5, 2018 bởi nguyenthao (9,000 điểm)
public static bool SetMachineName(string newName)
{
    RegistryKey key = Registry.LocalMachine;

    string activeComputerName = "SYSTEM\\CurrentControlSet\\Control\\ComputerName\\ActiveComputerName";
    RegistryKey activeCmpName = key.CreateSubKey(activeComputerName);
    activeCmpName.SetValue("ComputerName", newName);
    activeCmpName.Close();
    string computerName = "SYSTEM\\CurrentControlSet\\Control\\ComputerName\\ComputerName";
    RegistryKey cmpName = key.CreateSubKey(computerName);
    cmpName.SetValue("ComputerName", newName);
    cmpName.Close();
    string _hostName = "SYSTEM\\CurrentControlSet\\services\\Tcpip\\Parameters\\";
    RegistryKey hostName = key.CreateSubKey(_hostName);
    hostName.SetValue("Hostname",newName);
    hostName.SetValue("NV Hostname",newName);
    hostName.Close();
    return true;
}

...