Archive: Getting Hostname


Getting Hostname
VERY much a newbie to this and it's proving a steep learning curve.

I want to configure an installer that will read the current hostname of a Windows XP or Vista machine, store it for un-install purposes and then change the hostname. The searches I have made have told me little.

So far I have come across examples of code such as:-

System::Call "kernel32.dll::GetComputerNameW(t .r0,*i ${NSIS_MAX_STRLEN} r1)i.r2"

but I can't find anything I understand that tells me how to use this in a script and also what the various parameters are.

I would be grateful if someone could point me in the right direction.


that's not really typical NSIS scripting, as it invokes the System plugin that calls DLL functions (in this case, the function 'GetComputerNameW' in 'kernel32.dll'.

Example code with usage examples is provided in:
http://nsis.sourceforge.net/Your_Computer_Name (uses the registry rather than the GetComputerName functions)

http://nsis.sourceforge.net/User_Man...et_Server_Name


Thanks for the speedy response. I had come across the latter but couldn't see how to use the macro - part of this steep incline I'm following!! Is the ability to set the name just a mirror of GetComputerNameW using SetComputerNameW


naw, you'd have to look into:
http://msdn.microsoft.com/en-us/library/ms724931(VS.85).aspx
The System plugin documentation should tell you how/what, but that thing still confuses me half the time :\
Thankfully, this was covered on these Forums before, so:
http://forums.winamp.com/showthread.php?postid=2005624


I'm not sure if you could also write it out to the registry and use WM_WININICHANGE to notify the system of that change; so best to go with the above URL


This excellent the second link does the trick beautifully, many thanks. I'm not sure how I missed it when trawling for solutions, I try not to be a helpless newbie when I start something new. I am still very confused as to what the parameters mean etc. The MSDN link does not seem to offer much enlightenment on this point. I guess it will become apparent as I carry on.

Thanks again.


Well, the System plugin is a whole different world from NSIS scripting, it does some pretty raw handling of passing data into DLL functions, getting data back, etc.

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


That, for example, can be broken up into:

System:: ; invoke something in the System plugin
::Call ; specifically, the Call function.

That's NSIS's standard syntax for calling a plugin function.

The parameters for that function follow within the ' single quotes:

kernel32.dll:: ; Invoke something within the kernel32 DLL file
::SetComputerNameExA ; Specifically, the SetComputerNameEx function. It ends here in A so that the ANSI version is called, specifically.


SetComputerNameEx is, again, 'documented' over at:
http://msdn.microsoft.com/en-us/library/ms724931(VS.85).aspx

The parameters for that function follow within the ( ) parentheses:

i 5 ; The first parameter is an integer number, the number 5
t "$ComputerName" ; The second parameter i text, the string that follows ($ComputerName is an NSIS variable declared earlier).


Those two parameters follow from that function's description page at MSDN. It takes two parameters:

the COMPUTER_NAME_FORMAT to set, which is detailed further on the link given on that MSDN page to: http://msdn.microsoft.com/en-us/library/ms724224(VS.85).aspx (the one you'd be interested in, !define ComputerNamePhysicalDnsHostname, is the 6th item in that list - but they start counting at 0 (zero), so the number to use is 5)

And the actual name to set. The MSDN page shows that it actually wants a pointer to a buffer in the memory that holds the string, but the System plugin is smart enough to do that work for you and just lets you specify the text directly.

Finally, you may want to check if it worked or not, so you need the output from that function. That's define behind the parentheses:
i.r1

That means that the expected result should be of an integer type (the MSDN page shows that the result should be a BOOL, which basically means it will return an integer value of either 0 (zero, false) or 1 (one, true), and that you want to store that result in $1. Note that dot in front of 'r1', that would normally be the input value as far as the System plugin goes.. but obviously there's no input to give for the -result- of a function, so you can tell System that there is no input value by using that dot.

I'm probably not the best at explaining the finer details of the System plugin (still grappling with it a bit myself).. I'd say have a peek at the System plugin documentation, the various examples for it, and search the forums for other uses. It's *very* powerful, but whenever I can, I stay very far away from it :)

Brilliant thanks again for all the help. This has opened up much more for me. The help you gave me before has meant I have already been able to start to develop the installer I need and this is icing on the cake.