Changing the computer name

  • Thread starter Thread starter Wayne Taylor
  • Start date Start date
W

Wayne Taylor

Is there any way I can change the computer name using vb.net ?

thanks in advance
 
Hi,

I believe you will have to PInvoke the Win32 API functions SetComputerName
or SetComputerNameEx.

enum COMPUTER_NAME_FORMAT
{
ComputerNameNetBIOS,
ComputerNameDnsHostname,
ComputerNameDnsDomain,
ComputerNameDnsFullyQualified,
ComputerNamePhysicalNetBIOS,
ComputerNamePhysicalDnsHostname,
ComputerNamePhysicalDnsDomain,
ComputerNamePhysicalDnsFullyQualified,
ComputerNameMax
}

[DllImport("Kernel32")]
static extern bool SetComputerNameEx( [In] COMPUTER_NAME_FORMAT NameType,
string lpBuffer );

Regards

Chris Taylor
 
The machine name is stored on these registry keys:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters

You can change the computer name by modifying the relevant values in the
above keys.
Don't forget to reboot for the changes to be applied.

An easier way would be using WMI: the Win32_ComputerSystem class has a
Rename method
that you can use. However, this only exists on WinXP and above.

Cheers
 
Back
Top