Archive: API SetComputerName


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.

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?

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

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


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


System::Call 'kernel32.dll::SetComputerNameExA(i 5,t "$ComputerName")i.r1'


This one works.
thx