How to change Computer Name -- not just NetBIOS Computer Name

D

Dr. StrangeDub

Leaving network identification/DNS out of the picture, how does one
change the name of a computer in a local Workgroup (in C#)?

I implemented the SetComputerName() API call and that only seems to
change the NetBIOS Computer Name. I've verified that the underlying
registry key value that gets changed is:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName

Is there a recommended API (via Active Directory or WMI or Win32) for
finishing the job and getting the local Computer Name changed?

Any help here greatly appreciated -- I'm under the gun on this one...

Michael Rose
-Unisys Corp
 
M

Mattias Sjögren

Is there a recommended API (via Active Directory or WMI or Win32) for
finishing the job and getting the local Computer Name changed?

SetComputerNameEx ?



Mattias
 
D

Dr. StrangeDub

OK, thanks to Mattias I believe the API I want to use is
SetComputerNameEx. Now I just need to know how to invoke this from
C#. That is, does anyone know the P/Invoke definition for importing
this? Here's what I have for SetComputerName:
// PInvoke signature for SetComputerName in Kernel32.DLL
[DllImport("kernel32.dll")]
static extern bool SetComputerName(string lpComputerName);

I need the analogous PInvoke signature for SetComputerNameEx.

-Michael Rose
 
M

Mattias Sjögren

Michael,
That is, does anyone know the P/Invoke definition for importing
this?

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

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



Mattias
 
D

Dr. StrangeDub

Hey, thanks again Mattias.....Glad to see that the P/Invoke signature
I ended up implementing (after a co-worker found the info) matches
exactly with what you entered.

Thanks again,
-Michael Rose
Unisys Corp

Michael,
That is, does anyone know the P/Invoke definition for importing
this?

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

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



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top