The Glimmerman
9th August 2006 12:05 UTC
API SetComputerName
I want to set my computername with an api call.
StrCpy $ComputerName "TestName"
System::Call 'kernel32.dll::SetComputerName???(t "$ComputerName") i .r0'
I tried SetComputerName, SetComputerNameA, SetComputerNameEx, SetComputerNameExw.
If I use
System::Call 'kernel32.dll::SetComputerName(t "$ComputerName") i .r0'
The Computername is inserted in the registry, but the name isn't changed.
I read on
MSDN something about
COMPUTER_NAME_FORMAT
I think i'm missing something.
Hope that someone can help me.
Joel
9th August 2006 15:12 UTC
I think i'm missing something.
Awnser
MSDN something about COMPUTER_NAME_FORMAT
You can see that the function need 2 params and you are using one, right?
The Glimmerman
9th August 2006 15:42 UTC
I know.
But how do i define that.
I tried several things like
SetComputerName(t "ComputerNamePhysicalDnsHostname" , t "$ComputerName") i .r0'
SetComputerName(${ComputerNamePhysicalDnsHostname} , t "$ComputerName") i .r0'
But that doesn't work.
$0 gives an error
Afrow UK
9th August 2006 17:04 UTC
I'm guessing that this will work:
SetComputerName(i 5 , t "$ComputerName") i .r0'
COMPUTER_NAME_FORMAT is an enumeration, and ComputerNamePhysicalDnsHostname is the 6th item.
-Stu
CancerFace
10th August 2006 08:19 UTC
Afrow UK is right, it is an enumeration:
# ComputerNameNetBIOS 0
# ComputerNameDnsHostname 1
# ComputerNameDnsDomain 2
# ComputerNameDnsFullyQualified 3
# ComputerNamePhysicalNetBIOS 4
# ComputerNamePhysicalDnsHostname 5
# ComputerNamePhysicalDnsDomain 6
# ComputerNamePhysicalDnsFullyQualified 7
Better use
SetComputerNameEx. Try to set with
ComputerNamePhysicalNetBIOS and
ComputerNamePhysicalDnsHostname. If you get an error then use SetComputerName. Something like this:
...
System::Call 'kernel32.dll::SetComputerNameExA(i 4,t "$ComputerName")i.r1'
System::Call 'kernel32.dll::SetComputerNameExA(i 5,t "$ComputerName")i.r1'
StrCmp $1 0 +1 +2
System::Call 'kernel32.dll::SetComputerNameA(t "$ComputerName")i .r1'
...
The above code was generated from the example shown
here.
CF
The Glimmerman
10th August 2006 12:47 UTC
System::Call 'kernel32.dll::SetComputerNameExA(i 5,t "$ComputerName")i.r1'
This one works.
thx