469,600 Members | 2,326 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,600 developers. It's quick & easy.

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

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\Contro l\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
Jul 21 '05 #1
4 13849
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jul 21 '05 #2

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

On Thu, 19 Feb 2004 13:19:44 -0600, Dr. StrangeDub
<st********@yahoo.com> wrote:
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\Contr ol\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


Jul 21 '05 #3
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jul 21 '05 #4
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

On Fri, 20 Feb 2004 01:05:26 +0100, Mattias Sjögren
<ma********************@mvps.org> wrote:
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


Jul 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by memememe | last post: by
2 posts views Thread by XiScO | last post: by
5 posts views Thread by Steve McKewen | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.