Skip to content
⌘ NSIS Forum Archive

How to replace a text with machine name

4 posts

Alstom#

How to replace a text with machine name

hi, I want to replace a text with the machine name. How do i write the machine name in here??

Push "localhost" #-- text to be replaced within the " "
Push "$COMPUTERNAME" #-- replace with anything within the " "
Push all #-- replace all occurrences
Push all #-- replace all occurrences
Push $EXEDIR\file.txt #-- file to replace in
Call AdvReplaceInFile #-- Call the Function

How to replace the "$COMPUTERNAME" with the machine name??
zbd#
I would use a Var and not a define, so

; to access system info, include system plugin
!include "System.nsh"

; variable the computer name will be written to
Var COMPUTERNAME
Then in a section (probably .onInit Section) put this code to write the name to the variable specified above

; Read the computer name from system
System::Call "kernel32::GetComputerName(t .r0, *i ${NSIS_MAX_STRLEN})"
; Write the return to the Variable
StrCpy $0 $COMPUTERNAME
then just wherever u want it to say the computer name, have $COMPUTERNAME

hope it helps
p.s. not too sure if it works with 98, works with XP/2000