This appears to formatted in Visual C++ which I don't have :(
Thank you though
Main Topics
Browse All Topicsdoes anyone have sample code for changing the computer name via SetComputernameEX
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Heres another for you
This one definately works.
Careful with changing the value (COMPUTER_NAME_FORMAT.Comp
As MDSN says
ComputerNamePhysicalNetBIO
Warning: Using this option to set the NetBIOS name breaks the convention of interdependent NetBIOS and DNS names. Applications that use the DnsHostnameToComputerName function will fail if this convention is broken.
Enum COMPUTER_NAME_FORMAT
ComputerNameNetBIOS ' unused for this call
ComputerNameDnsHostname ' unused for this call
ComputerNameDnsDomain ' unused for this call
ComputerNameDnsFullyQualif
ComputerNamePhysicalNetBIO
ComputerNamePhysicalDnsHos
ComputerNamePhysicalDnsDom
ComputerNamePhysicalDnsFul
ComputerNameMax
End Enum
Declare Function SetComputerNameEx Lib "kernel32" Alias "SetComputerNameExA" (ByVal NameType As COMPUTER_NAME_FORMAT, ByVal lpBuffer As String) As Long
Public Function SetComputerName(strCompute
SetComputerName = SetComputerNameEx(COMPUTER
End Function
Be Careful.
Are you just trying to set the computer name, because if you are the SetComputerName API is a lot simpler.
Corrected version of mine which you can paste into a form with one button:
Option Explicit
'BOOL SetComputerNameEx(
' COMPUTER_NAME_FORMAT NameType, // name type
' LPCTSTR lpBuffer // new name buffer
');
Private Const ComputerNamePhysicalNetBIO
Private Const ComputerNamePhysicalDnsHos
Private Const ComputerNamePhysicalDnsDom
Private Declare Function SetComputerNameEX Lib "kernel32" Alias "SetComputerNameExA" (ByVal lngType As Long, ByVal lpComputerName As String) As Long
Private Sub Command1_Click()
Dim strName
Dim lngRet As Long
strName = "Mikey"
strName = strName & Chr(0)
lngRet = SetComputerNameEX(Computer
End Sub
Alright let me explain what I'm doing more in depth I'm trying to have have a program that among other things changes both the DNS and NETBIOS name just like when you change it from the my computer properties. The only thing it needs is to be able to take text input from the user and set that as the name, then reboot the machine. It will be added later to a program that adds user and changes some passwords / ip's etc....
Business Accounts
Answer for Membership
by: PaulHewsPosted on 2000-06-09 at 10:59:19ID: 2921242
Note: The ComputerName..constants are pulled from an Enum, which will be long values. I converted this from MSDN docs, but I cannot test it, as I do not have Win 2000.
S = 4& tname = 5& ain = 6&
NamePhysic alNetBIOS, strName)
Option Explicit
'BOOL SetComputerNameEx(
' COMPUTER_NAME_FORMAT NameType, // name type
' LPCTSTR lpBuffer // new name buffer
');
Private Const ComputerNamePhysicalNetBIO
Private Const ComputerNamePhysicalDnsHos
Private Const ComputerNamePhysicalDnsDom
Private Declare Function SetComputerNameEX Lib "kernel32" Alias "SetComputerNameEx" (ByVal lngType As Long, ByVal lpComputerName As String) As Long
Private Sub Command1_Click()
Dim strName
Dim lngRet As Long
strName = "Mikey"
strName = strName & Chr(0)
lngRet = SetComputerNameEX(Computer
End Sub
Hope this helps :)