Archive: Subtracting Characters from a line of text


Subtracting Characters from a line of text
Forgive me I'm new to this whole NSIS scripting thing. I've searched up and down everywhere for this and cannot find anything. I'm looking to pull the registry information for the ProductID for WinXP and then subtract the last couple characters off of it since it seems the first three sets of numbers are the same.

The end goal of this function or line of code is to be able to verify if the PC the installer is running on is a corporate supported PC.

XXXXX-XXX-XXXXXXX-XXXXX

Above is the normal format for the ProductID key in the registry. I'm looking to chop off the bits underlined and put it into a variable so that I can compare it using the StrCmp command. I already have the code to pull the value from the registry and put it as the variable $1 but from there I'm lost.

I'm not looking for someone to write the code for me or anything but if someone can point me in the right direction as to which commands can do this that would be much appreciated. Thanks in advance.


look at the StrCpy command

StrCpy $0 "a string" # = "a string"
StrCpy $0 "a string" 3 # = "a s"
StrCpy $0 "a string" -1 # = "a strin"
StrCpy $0 "a string" "" 2 # = "string"
StrCpy $0 "a string" "" -3 # = "ing"
StrCpy $0 "a string" 3 -4 # = "rin"

Yathosho beat me to it! But since I had my reply all ready so go, I'll submit it anyway:

If the part you want to get always 5 characters, then you could use StrCpy as Yathosho points out:

StrCpy $2 "$1" "" -5


Else, you'd have to split at the last dash. To do that, one might use this:
!include WordFunc.nsh
!include Logiclib.nsh
!insertmacro WordFind
...

; let's say $1 is the long string:
${WordFind} "$1" "-" "-1" $2
; $2 should be your string
${If} "$2" == ""
MessageBox MB_OK "Invalid product code!"
${EndIf}

(Both StrCpy and WordFind are in the NSIS help files if you need more info.)

edit: forgot the !insertmacro command in my example...

Thanks to both of you. Using the above examples I came up with a working demo script which will be merged in my main script tomorrow. I thought this NSIS stuff was going to be hard but in reality its not as bad as I thought!

If it helps anyone this is what I wrote:



ReadRegStr $1 HKLM "Software\Microsoft\Windows NT\CurrentVersion" "ProductId"
StrCpy $2 "$1" -6
IfFileExists "c:\corporatecomputer.txt" "+3" "+1"
StrCmp $2 "34534-OEM-4636364" "+2" "+1"
StrCmp $2 "56345-OEM-3642634" "+1" "NotCorporate"

MessageBox MB_OK 'The value was good!'
Goto Finish

NotCorporate:
MessageBox MB_OK 'Setup cannot continue because this is not a Corporate Computer. $8'
Quit


I had to put a backdoor in there so thats where the corporatecomputer.txt comes in to play. Thanks again!