Old 21st August 2007, 01:46   #1
vbguy
Junior Member
 
Join Date: Jul 2006
Posts: 30
Question Post installer-build events?

I want to execute a signing tool after the installer has been built, and I want to do it within the script.

Right now I have:

!system 'Signing\SignMe.exe "Releases\installer.exe"'

at the end of the NSI file, but this signs the file before it has been really created.

Is there a way to sign the installer after it has been made? Also, how would I be able to reference the OutFile location, without hardcoding the output path?
vbguy is offline   Reply With Quote
Old 21st August 2007, 02:28   #2
michaelcsikos
Junior Member
 
Join Date: Dec 2005
Location: Brisbane, Australia
Posts: 16
Why don't you just make a build.bat file to build your installer?
code:
"C:\Program Files\NSIS\makensis.exe" "My Installer.nsi"
Signing\SignMe.exe "Releases\installer.exe"



If you put the batch file in the same folder as the .nsi file it should all work.
michaelcsikos is offline   Reply With Quote
Old 21st August 2007, 02:54   #3
vbguy
Junior Member
 
Join Date: Jul 2006
Posts: 30
Well, normally I would do that but I'm running a number of post installer-build events and I want them to all use the OutFile variable, and if that's not possible I'd still like them all in the same place.

Is it impossible to run a command within the nsi file after the installer has been built?
vbguy is offline   Reply With Quote
Old 21st August 2007, 03:36   #4
michaelcsikos
Junior Member
 
Join Date: Dec 2005
Location: Brisbane, Australia
Posts: 16
I don't know of a way to do a post build event from within an NSIS script.

You could pass in the OutFile to the build batch file and pass it along to makensis. Then you can use the variable for whatever post events you want:
code:
@echo off

IF "%~1"=="" (
echo Usage: build OutFile.exe
pause
exit
) ELSE (SET OutFile=%~1)

"C:\Progam Files\NSIS\makensis.exe" "My Installer.nsi" "/XOutFile %OutFile%"
NSIS\makensis.exe "My Installer.nsi" "/XOutFile %OutFile%"
Signing\SignMe.exe "Releases\%OutFile%"
xcopy "Releases\%OutFile%" \\MyServer\Backup
...
pause

michaelcsikos is offline   Reply With Quote
Old 21st August 2007, 04:31   #5
Red Wine
Forum King
 
Red Wine's Avatar
 
Join Date: Mar 2006
Location: Ath. GR
Posts: 2,078
SignMe.exe should be used same way as an external packer,

http://nsis.sourceforge.net/Docs/Chapter5.html#5.1.10

Quick AVI Creator - Quick and easy convert from DVD/MPEG/AVI/MKV to AVI/MP4/MKV
Quick AVI Creator entirely edited with NSIS and entirely upgraded to Unicode NSIS
Red Wine is offline   Reply With Quote
Old 21st August 2007, 06:43   #6
demiller9
Senior Member
 
Join Date: Mar 2006
Location: Dallas
Posts: 462
You can use !execute or !system, but they both wait for the called program to finish before they let makensis finish.

If you !execute a program that will start another one (and not wait for it to finish), you could have your second program wait for makensis to complete, and then do the commands you are trying to do.

Rather round-about, but possible.

Don
demiller9 is offline   Reply With Quote
Old 21st August 2007, 07:25   #7
demiller9
Senior Member
 
Join Date: Mar 2006
Location: Dallas
Posts: 462
Here's a vbscript that can wait for makensis to exit, and then call SignMe.exe. Put this into a file called SignNsi.vbs, in the same folder as your nsi script:
code:
Set sh=Wscript.CreateObject("WScript.Shell")
Set wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

ExeName = Wscript.Arguments(0)
WQL = "Select Name from Win32_Process Where Name='makensis.exe'"

Do While MakeNsisActive
Wscript.Sleep 250
Loop

sh.Run "Signing\SignMe.exe Releases\" & ExeName

Function MakeNsisActive
MakeNsisActive = CBool(Wmi.ExecQuery(WQL).Count > 0)
End Function



Here's the code that would go at the end of the NSIS script. Note that I have used a define called FILENAME for the output file, and used your relative path Releases:
code:
!define ExeName "Releases\${FILENAME}"
!tempfile FILE
!appendfile "${FILE}.vbs" 'set s=CreateObject("WScript.Shell")$\n'
!appendfile "${FILE}.vbs" 's.run "wscript SignNsi.vbs ${ExeName}",0,False$\n'
# execute (and wait for) the two-line script above
!execute "wscript ${FILE}.vbs"
# delete the vbs and tempfile now
!delfile "${FILE}.vbs"
!delfile "${FILE}"


Don
demiller9 is offline   Reply With Quote
Old 21st August 2007, 14:10   #8
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,442
you dont need the first script(edit: last in your post, but the first executed ), something like

!execute '$%COMSPEC% /c start wscript.exe SignNsi.vbs ${ExeName}'

should probably do it

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 21st August 2007, 16:02   #9
demiller9
Senior Member
 
Join Date: Mar 2006
Location: Dallas
Posts: 462
During the testing I did before I posted, it looked like makensis waited for the %COMSPEC% program to complete before it creates the final installer (nsi executable). The first script I call terminates (after starting the second one) and thus the installer gets created.

I'll repeat the testing to confirm it.

Don
demiller9 is offline   Reply With Quote
Old 21st August 2007, 16:28   #10
demiller9
Senior Member
 
Join Date: Mar 2006
Location: Dallas
Posts: 462
@Anders: I see, you combined COMSPEC and Start. I agree with you, it works and that simplifies the code at the end of the nsi script.

I notice that I have the path Release coded in the vbscript and also added it in the !define ExeName before calling the vbscript. One of them should be removed.

Don
demiller9 is offline   Reply With Quote
Old 31st August 2007, 07:24   #11
vbguy
Junior Member
 
Join Date: Jul 2006
Posts: 30
Red Wine: That signs the installer before it has been fully created, thus the signature is valid for an incomplete installer, but invalid for the entirely complete installer.

Demiller9: Your method worked, though I ended up writing a small c# console program instead of vbscript, mainly because I wouldn't be able to maintain the script. But your idea of waiting for makensis to exit made the difference.

I still have one problem though: I have

code:
OutFile "Releases\setup.exe"


defined in the script. Is there a way to reference the OutFile variable? Namely, to pass it as commandline argument. Right now I have to redefine the output location when I sign the file:

code:
!system '"Signing\SignMe.exe" "Releases\setup.exe" /w'


I've tried $EXEPATH, but that seems to be an install-time variable.
vbguy is offline   Reply With Quote
Old 31st August 2007, 14:56   #12
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,442
you could use a define.

Maybe someone should add a feature request for something like !systemEOF or something that executes after makensis is done writing to the installer

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 31st August 2007, 15:42   #13
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
I requested for something similar, !macro CompileDone or something it was. I think the answer currently is to use a batch file.

Stu
Afrow UK 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