Old 8th September 2006, 07:59   #1
mayPol
Junior Member
 
Join Date: Jul 2006
Posts: 23
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
mayPol is offline   Reply With Quote
Old 8th September 2006, 10:29   #2
{_trueparuex^}
Senior Member
 
{_trueparuex^}'s Avatar
 
Join Date: Dec 2005
Location: Glow
Posts: 285
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.
code:
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:



Better way would be using system plug-in and call GetComputerName with it. I really don't understand all those cryptic system plug-in calls so I won't write example code here, but maybe someone else will Anyone...?

The guy with the ridiculous username. Thou shall call him PaR instead.
Visit My Website

Last edited by {_trueparuex^}; 8th September 2006 at 10:44.
{_trueparuex^} is offline   Reply With Quote
Old 8th September 2006, 10:53   #3
mayPol
Junior Member
 
Join Date: Jul 2006
Posts: 23
Thanks. It's greate
mayPol is offline   Reply With Quote
Old 18th December 2007, 16:06   #4
LuP
Junior Member
 
Join Date: Jan 2007
Location: Praha, Czech Republic
Posts: 13
... How to get computer name via System::Call (...???) GetComputerName (LPCSTR buf, DWORD size)?

- I don't understand system function call conventions...

Thanks.

LuP
LuP is offline   Reply With Quote
Old 18th December 2007, 16:52   #5
pospec
Senior Member
 
pospec's Avatar
 
Join Date: Jun 2007
Location: Otrokovice, Czech Republic
Posts: 308
I don't understand system function call conventions...
Neither do I
pospec is offline   Reply With Quote
Old 18th December 2007, 17:03   #6
LuP
Junior Member
 
Join Date: Jan 2007
Location: Praha, Czech Republic
Posts: 13
... 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
LuP is offline   Reply With Quote
Old 18th December 2007, 18:18   #7
CancerFace
Senior Member
 
Join Date: Apr 2006
Posts: 289
Send a message via ICQ to CancerFace
Quote:
... 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:
code:
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).
You can use GetComputerNameEx which gives a bit more info:
code:
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:
code:
; ComputerNameNetBIOS 0
; ComputerNameDnsHostname 1
; ComputerNameDnsDomain 2
; ComputerNameDnsFullyQualified 3
; ComputerNamePhysicalNetBIOS 4
; ComputerNamePhysicalDnsHostname 5
; ComputerNamePhysicalDnsDomain 6
; ComputerNamePhysicalDnsFullyQualified 7


Hope this helps,

CF
CancerFace is offline   Reply With Quote
Old 18th December 2007, 18:32   #8
LuP
Junior Member
 
Join Date: Jan 2007
Location: Praha, Czech Republic
Posts: 13
... 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
LuP is offline   Reply With Quote
Old 18th December 2007, 19:16   #9
pospec
Senior Member
 
pospec's Avatar
 
Join Date: Jun 2007
Location: Otrokovice, Czech Republic
Posts: 308
Nice! Thank you CancerFace
pospec is offline   Reply With Quote
Old 26th September 2010, 18:41   #10
nsnb
Senior Member
 
Join Date: Jul 2008
Posts: 157
Smile

Quote:
Originally Posted by {_trueparuex^} View Post
Better way would be using system plug-in and call GetComputerName with it
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
nsnb is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump