开发者

Change computer name

We use Configuration managar to install operating systems, that for some genius reason does not have a simple way to set rules for machine开发者_JS百科 names.

So im looking for a C# API that allows me to change the computer name ( NETBIOS) and change it in Active directory at the same time. I want to set the name AFTER im connected to AD so i can check if the machine had a old name and belonged to a none spesfic OU.

I have tried:

[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
static extern bool SetComputerNameEx(COMPUTER_NAME_FORMAT NameType,string lpBuffer);

This one does change the local machine name, but this will corrupt the AD connection.


For all Windows OSes since XP you can simply use the command-line program NETDOM.EXE to change the computer name on both the machine itself and Active Directory... no programming required.


string newName = "newName";

RegistryKey key = Registry.LocalMachine.OpenSubKey("SYSTEM", true).OpenSubKey("CurrentControlSet", true).OpenSubKey("Services", true).OpenSubKey("tcpip", true).OpenSubKey("Parameters", true);

key.SetValue("Hostname", newName);
key.SetValue("NV Hostname", newName);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜