Archive: Changing machine name (hostname)


Changing machine name (hostname)
By using this forum, I found a way of getting the hostname for the current machine.
That was (all things compared) relatively easy...
Now, I'd like my installer to change the computer name... that's much less easy, it seems...


This must do the trick


Function GetComputerName
System::Call 'kernel32.dll::GetComputerNameExW(i 4, w .r0, *i ${NSIS_MAX_STRLEN} r1) i.r2'
${If} $2 = 1
StrCpy $Localhost "\\$0"
${Else}
MessageBox MB_OK|MB_ICONSTOP 'Could not determine the computer name!$\nAborting...'
Quit
${EndIf}
System::Free $0
FunctionEnd

Function SetComputerName
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'
;System::Call 'kernel32.dll::SetComputerNameEx (i 5,t "$ComputerName") i.r0'
FunctionEnd

For User Management info.
Goto this page