Get local machine name
Hi,
How can I get in the NSIS the local machine name. I checked the constants and didn't find a sutable one.
Thanks,
May
Archive: Get local machine name
Get local machine name
Hi,
How can I get in the NSIS the local machine name. I checked the constants and didn't find a sutable one.
Thanks,
May
One way is to read it from registry...
HKLM\System\CurrentControlSet\Control\ComputerName\ComputerName ComputerName
This key should exist from windows 95 to windows XP (not sure about NT). There is also other key (HKLM System\...\ComputerName\ActiveComputerName ComputerName)
containing the computer name and this should be the "right" key to read the computer name, but as far as I know this key doesn't exist in windows 9x systems.
I am using code like this, to read the name from registry.
ReadRegStr $0 HKLM "System\CurrentControlSet\Control\ComputerName\ActiveComputerName" "ComputerName"
StrCmp $0 "" 0 nameok
ReadRegStr $0 HKLM "System\CurrentControlSet\Control\ComputerName\ComputerName" "ComputerName"
StrCmp $0 "" 0 nameok
MessageBox MB_ICONSTOP|MB_OK "Couldn't resolve computer name!"
Abort
nameok:
Thanks. It's greate:up:
... How to get computer name via System::Call (...???) GetComputerName (LPCSTR buf, DWORD size)?
- I don't understand system function call conventions...
Thanks.
LuP
I don't understand system function call conventions...
Neither do I :(
... I tried something like this:
System::Call 'kernel32::GetComputerName(t.r0, *i.${NSIS_MAX_STRLEN} r1) i.r2'
MessageBox MB_OK $R0
MessageBox MB_OK $R1
MessageBox MB_OK $R2
But all three message boxes display nothing :-(
LuP
... But all three message boxes display nothing :-(That's because you are looking in $R0,$R1,$R2 but your system call uses $0, $1 and $2 (namely r0, r1 and r2). The correct call is:
System::Call 'kernel32.dll::GetComputerNameA(t .r0,*i ${NSIS_MAX_STRLEN} r1)i.r2'
$0 will contain the computer name, $1 will get the number of characters of that name (+1) and $2 will be zero if the function fails (or any number if the function succeeds).
System::Call 'kernel32.dll::GetComputerNameExA(i 4, t .r0,*i ${NSIS_MAX_STRLEN} r1)i.r2'
will get you in $0 the ComputerNamePhysicalNetBIOS. Or just follow the enumeration:
; ComputerNameNetBIOS 0
; ComputerNameDnsHostname 1
; ComputerNameDnsDomain 2
; ComputerNameDnsFullyQualified 3
; ComputerNamePhysicalNetBIOS 4
; ComputerNamePhysicalDnsHostname 5
; ComputerNamePhysicalDnsDomain 6
; ComputerNamePhysicalDnsFullyQualified 7
... Thanks, you helped me much - I may start understanding this all about System::...
I use this code (I realized I need to get user name):
System::Call "advapi32::GetUserName(t.R0, *i${NSIS_MAX_STRLEN}.R1) i.R2"
StrCpy $BatDir "C:\$R0\Bat"
Thanks a lot.
LuP
Nice! Thank you CancerFace
Originally posted by {_trueparuex^}Why is it a better way? System's GetComputerName gets this value from the registry, too, just as exemplified here: http://nsis.sourceforge.net/Your_Computer_Name
Better way would be using system plug-in and call GetComputerName with it