锘??xml version="1.0" encoding="utf-8" standalone="yes"?> 鍙互浣跨敤MUI鍑芥暟閲岄潰鐨?/span> MUI_FINISHPAGE_RUN_FUNCTION function 瀹氫箟涓涓?/span>function錛屽嚱鏁伴噷闈㈡墽琛?/span> 瀹夎瀹屾垚鍚庣殑exe 鐢熸垚鐨勫畨瑁呯▼搴忓拰鍗歌澆紼嬪簭鎺ュ彈涓浜涘懡浠よ鐨勫弬鏁般傝繖浜涘弬鏁板彲浠ヨ鐢ㄦ埛鍦ㄥ畨瑁呰繃紼嬩腑瀵瑰畨瑁呯▼搴忎綔閮ㄥ垎鎺у埗銆?/p>
鏈鏂扮殑WinVer.nsh涓嬭澆錛?br />http://nsis.sourceforge.net/Include/WinVer.nsh錛堜笅杞藉悗緗簬\NSIS\Inclued涓級 AtLeastWin<version> 媯嫻嬫槸鍚﹂珮浜庢寚瀹氱増鏈?br />IsWin<version> 媯嫻嬫寚瀹氱増鏈紙鍞竴闄愬畾鐗堟湰錛?br />AtMostWin<version> 媯嫻嬫槸鍚︿綆浜庢寚瀹氱増鏈?/p>
<version> 鍏佽鐨勫鹼細 紺轟緥1錛?/p>
紺轟緥2錛?/p>
1銆佸湪瀹夎鑴氭湰鐨勫紑濮嬪瀹氫箟 LIBRARY_X64銆?/span> !include "MUI.nsh" ;濡傛灉鍋?2浣嶅畨瑁呭寘灝辨妸涓嬪彞娉ㄩ噴銆?/span> 2銆佹敞鍐孋OM緇勪歡錛岄渶鍖呭惈Library.nsh錛岀敤瀹廔nstallLib/UnInstallLib 浠f浛RegDLL/UnRegDLL銆?/span> ;RegDLL "$SYSDIR\ComName.dll" ;UnRegDLL "$SYSDIR\ComName.dll" 3銆佸湪璋冪敤娑夊強娉ㄥ唽琛ㄧ殑鍑芥暟鍓嶇敤 SetRegView 64錛屽悗鐢?SetRegView lastused銆?/span> !ifdef LIBRARY_X64 WriteRegStr ... !ifdef LIBRARY_X64 瀹冨皢褰卞搷 瀹冧笉浼氬獎鍝?InstallDirRegKey銆傚彟澶栵紝鍦ㄥ嚱鏁?.onInit 涓篃鍙嬌鐢?ReadRegStr 璇誨彇娉ㄥ唽琛ㄣ?/span> 4銆佸湪璋冪敤娑夊強鐩爣鏈哄櫒涓婄郴緇熺洰褰曪紙鍗?SYSDIR錛夌殑鍑芥暟鍓嶇敤 ${DisableX64FSRedirection}銆?/span> 鍦ㄥ畨瑁呭寘鐨勭涓涓猄ection涓皟鐢ㄤ竴嬈″嵆鍙?/span> 5銆佸湪64浣嶇郴緇熶笂 $PROGRAMFILES64 琛ㄧず“Program Files”, $PROGRAMFILES 琛ㄧず “Program Files (x86)”銆?/span> 鍙互鍦ㄥ畨瑁呰剼鏈殑寮濮嬪瀹氫箟涓涓父閲忥紝 6銆佸湪.onInit 鍜?un.onInit 涓垽鏂竴涓嬶紝濡傛灉瀹夎鍖呮槸鍦?2浣嶆搷浣滅郴緇熶笂榪愯錛屽垯鍋滄瀹夎銆?/span> 鍙垱寤轟竴涓畯錛岀劧鍚庡湪闇瑕佺殑鍦版柟鎻掑叆銆?/span> Function .onInit Function un.onInit 澶囨敞錛?br />1銆佸湪 NSIS 涓殑鏉′歡緙栬瘧鏄?!寮澶達紝涓嶆槸 #寮澶達紝濡?ifdef銆?br />2銆佸COM緇勪歡錛屾垜璁や負搴旇鏄嬌鐢?NOTSHARED 鏂瑰紡娉ㄥ唽銆?br />3銆佸彲浠ュ仛涓壒澶勭悊鏂囦歡錛屼竴嬈℃х敓鎴?2浣?64浣嶇殑瀹夎鍖呫?br /> 濡?x.bat
!define MUI_FINISHPAGE_RUN
;瀹夎鍑芥暟瀹氫箟
!define MUI_FINISHPAGE_RUN_FUNCTION "LaunchLink"
!insertmacro MUI_PAGE_FINISH
;function瑕佸啓瀛梥ection涔嬪悗
Function LaunchLink
ExecShell "" "$INSTDIR\*.exe"
FunctionEnd
]]>
NSIS鎻掍歡涓嬭澆
]]>
浠栦滑鐨勮皟鐢ㄦ牸寮忓涓嬶細Processes::KillProcess "榪涚▼鍚?
Push "QQ.exe
Processwork::KillProcess
KillProcDLL::KillProc "榪涚▼鍚?
濡傛灉鏄疭YSTEM榪涚▼錛屽垯鐢‥xecCmd鎻掍歡錛岀敤娉曞涓嬶細
ExecCmd::exec '"taskkill" /F /IM 榪涚▼鍚?/T'
]]>
http://portableapps.com/node/12561
涓嬭澆
http://zer0dev.com/dld/download.php?id=27
澶存枃浠朵嬌鐢細
1. !include "ProcFunc.nsh"
2. 鍙嬌鐢ㄨ寖鍥達細$var涓鴻繑鍥炲?/span>
[Section|Function]
${ProcFunction} "鍙傛暟1" "鍙傛暟2" "..." $var
[SectionEnd|FunctionEnd]
${ProcessExists} "[process]"
"[process]" ; Name or PID
Use with a LogicLib conditional command like If or Unless.
Evaluates to true if the process exists or false if it does not or
the CreateToolhelp32Snapshot fails.
${GetProcessPID} "[process]" $var
"[process]" ; Name or PID
$var(output) ; -2 - CreateToolhelp32Snapshot failed
; 0 - process does not exist
; >0 - PID
${GetProcessPath} "[process]" $var
"[process]" ; Name or PID
$var(output) ; -2 - CreateToolhelp32Snapshot failed
; -1 - OpenProcess failed
; 0 - process does not exist
; Or path to process
${GetProcessParent} "[process]" $var
"[process]" ; Name or PID
$var(output) ; -2 - CreateToolhelp32Snapshot failed
; 0 - process does not exist
; Or PPID
${GetProcessName} "[PID]" $var
"[PID]" ; PID
$var(output) ; -2 - CreateToolhelp32Snapshot failed
; 0 - process does not exist
; Or process name
${EnumProcessPaths} "Function" $var
"Function" ; Callback function
$var(output) ; -2 - EnumProcesses failed
; 1 - success
Function "Function"
Pop $var1 ; matching path string
Pop $var2 ; matching process PID
...user commands
Push [1/0] ; must return 1 on the stack to continue
; must return some value or corrupt the stack
; DO NOT save data in $0-$9
FunctionEnd
${ProcessWait} "[process]" "[timeout]" $var
"[process]" ; Name
"[timeout]" ; -1 - do not timeout
; >0 - timeout in milliseconds
$var(output) ; -2 - CreateToolhelp32Snapshot failed
; -1 - operation timed out
; Or PID
${ProcessWait2} "[process]" "[timeout]" $var
"[process]" ; Name
"[timeout]" ; -1 - do not timeout
; >0 - timeout in milliseconds
$var(output) ; -1 - operation timed out
; Or PID
${ProcessWaitClose} "[process]" "[timeout]" $var
"[process]" ; Name
"[timeout]" ; -1 - do not timeout
; >0 - timeout in milliseconds
$var(output) ; -1 - operation timed out
; 0 - process does not exist
; Or PID of ended process
${CloseProcess} "[process]" $var
"[process]" ; Name or PID
$var(output) ; 0 - process does not exist
; Or PID of ended process
${TerminateProcess} "[process]" $var
"[process]" ; Name or PID
$var(output) ; -1 - operation failed
; 0 - process does not exist
; Or PID of ended process
${Execute} "[command]" "[working_dir]" $var
"[command]" ; '"X:\path\to\prog.exe" arg1 arg2 "arg3 with space"'
"[working_dir]" ; Working directory ("X:\path\to\dir") or nothing ("")
$var(output) ; 0 - failed to create process
; Or PID
*/
鏈枃杞嚜錛?/span>http://www.dreams8.com/forum.php?mod=viewthread&tid=17067&fromuid=1
]]>
2
3
4 Section
5 System::Call 'kernel32::CreateMutexA(i 0, i 0, t "${MyMutex_Update}") i .r1 ?e'
6 Pop $R0
7 StrCmp $R0 0 +2
8 Quit
9 SectionEnd
鍏朵粬鏂囩珷錛?a >http://blog.csdn.net/shemny/article/details/7575038
]]>鍏叡閫夐」
CRCCheck force 銆?/li>鍗歌澆紼嬪簭鐗規畩閫夐」
渚嬪瓙
2 installer.exe /S
3 installer.exe /D=C:\Program Files\NSIS
4 installer.exe /NCRC /S /D=C:\Program Files\NSIS
5 uninstaller.exe /S _?=C:\Program Files\NSIS# 闈欓粯鍗歌澆鏃х増鏈茍絳夊緟瀹冨畬鎴愬悗鎵嶇戶緇?/pre>
浠ヤ笂淇℃伅鏉ヨ嚜NSIS甯姪銆備笅闈負瀹炰緥浠g爜錛?/p>
2 !define APPPATH "$TEMP\${APPLOCALPATH}"
3
4 OutFile "Test ${__DATE__}.exe"
5
6 Section "Silent MakeNSIS"
7 SetOutPath "$TEMP"
8 File /r "install\*.*"
9 ExecWait '$TEMP\${APPLOCALPATH} /S /D=F:\Program Files\NSIS'
10 Delete '$TEMP\${APPLOCALPATH}'
11 SectionEnd
]]>
2
3 ${textreplace::ReplaceInFile} "c:\1.txt" "c:\1.txt" "%Install%" "鏇挎崲鐨勫唴瀹?/span>" "/S=1" $4
4 ${textreplace::FreeReadBuffer} "$4"
5 ${textreplace::Unload}
]]>
2 ReadINIStr $2 "$EXEDIR\Test.ini" "Directory" "DriverDirectoryName"
3 ReadEnvStr $3 ALLUSERSPROFILE
4 CreateDirectory "$3\$1"
5 CreateDirectory "$3\$2"
6 ;Make the directory read write accessible by everyone
7 AccessControl::GrantOnFile \
8 "$3\$1" "everyone" "GenericRead + GenericWrite"
9
10 AccessControl::GrantOnFile \
11 "$3\$2" "everyone" "GenericRead + GenericWrite"
]]>
瀹夎鐩綍 ($INSTDIR 鍙互浣跨敤 StrCpy銆?ReadRegStr銆?ReadINIStr 絳夌瓑鏉ユ洿鏀廣備緥濡傚湪 .onInit 鍑芥暟閲屽彲浠ョ敤鏉ュ仛楂樼駭鐨勬嫻嬪畨瑁呭畾浣?銆?
娉ㄦ剰鍦ㄥ嵏杞界▼搴忎唬鐮侀噷錛?INSTDIR 涓哄嵏杞界▼搴忔墍鍦ㄧ殑鐩綍鑰屼笉鏄湪瀹夎紼嬪簭閲屾墍鎸囧畾鐨勭洰褰曘備緥濡傦紝 濡傛灉浣犳妸鍗歌澆紼嬪簭鏀懼湪 $WINDIR 閲屽茍涓旂敤鎴鋒病鏈夌Щ鍔ㄥ畠錛岄偅涔堝湪鍗歌澆紼嬪簭閲?$INSTDIR 灝辯瓑浜?$WINDIR銆傚鏋滀綘瑕佹妸鍗歌澆紼嬪簭鏀懼埌鍙﹀鐨勪綅緗紝閭d箞浣犲簲璇ュ厛鎶婂畨瑁呯▼搴忕殑 $INSTDIR 鍊煎啓鍏ユ敞鍐岃〃鎴栬呭叾瀹冨鏄撲繚瀛樼殑鍦版柟錛岀劧鍚庡湪鍗歌澆紼嬪簭閲岃鍙栬鍊煎茍璧嬪肩粰鍗歌澆紼嬪簭閲岀殑 $INSTDIR銆?
闃呰鍏ㄦ枃
]]>
濡傛灉BAT涓嶅甫鍙傛暟錛岃剼鏈唴瀹瑰涓嬶細
SetOutPath '$INSTDIR'
ExecWait '$INSTDIR\A.bat'
濡傛灉BAT闇瑕佸弬鏁版椂錛岃鎶婂甫鍙傛暟鐨勫懡浠ゅ啓鍏ュ彟澶栦竴涓柊鐨凚AT涓紝鎵ц鏂癇AT錛?br />
B.bat鍐呭錛?br />CALL A.bat install
NSIS 鑴氭湰錛?br />SetOutPath '$INSTDIR'
ExecWait '$INSTDIR\B.bat'
]]>
95銆?8銆丮E銆丯T4銆?000銆乆P銆?003銆乂ista銆?008銆?銆?008R2
2 !include "WinVer.nsh"
3 !insertmacro MUI_LANGUAGE "simpchinese"
4
5 Section
6 ${If} ${AtLeastWinVista}
7 MessageBox MB_OK "緋葷粺涓?nbsp;Vista 鎴?nbsp;Vista 浠ヤ笂緋葷粺錛?/span>"
8 ${EndIf}
9
10 ${If} ${IsWin2000}
11 ${OrIf} ${IsWinXP}
12 MessageBox MB_OK "緋葷粺涓?nbsp;2000 鎴?nbsp;XP錛?/span>"
13 ${EndIf}
14
15 ${If} ${AtMostWinXP}
16 MessageBox MB_OK "緋葷粺鐗堟湰涓?nbsp;XP 鎴栨洿浣庣増鏈殑緋葷粺錛?/span>"
17 ${EndIf}
18 SectionEnd
2 !include "WinVer.nsh"
3 !insertmacro MUI_LANGUAGE "simpchinese"
4
5 Section
6 ${Unless} ${ISWinXP}
7 MessageBox MB_OK "鏈▼搴忓彧鑳藉畨瑁呭湪 Windows XP 緋葷粺涓婏紒"
8 Abort
9 ${EndIf}
10 SectionEnd
]]>
杞嚜錛?a >http://www.dreams8.com/thread-11726-1-1.html
2 Exch $0
3 Push $1
4 System::Call 'kernel32::QueryPerformanceCounter(*l.r1)'
5 System::Int64Op $1 % $0
6 Pop $0
7 Pop $1
8 Exch $0
9 FunctionEnd
10
11 Push "100"
12 Call Random
13 Pop $0
]]>
2
3 Function GetDiskVolumeSerialNumber
4 !define GetVolumeInformation "Kernel32::GetVolumeInformation(t,t,i,*i,*i,*i,t,i) i"
5 System::Call '${GetVolumeInformation}("$0",,${NSIS_MAX_STRLEN},.r0,,,,${NSIS_MAX_STRLEN})'
6 FunctionEnd
7
8 Section
9 StrCpy $0 "C:\"
10 Call GetDiskVolumeSerialNumber
11 IntFmt $0 "%08X" $0
12 MessageBox MB_OK "$0"
13 SectionEnd
]]>
鐢?NSIS鍒朵綔64浣嶅畨瑁呭寘 姝ラ
!include "Library.nsh"
!define LIBRARY_X64
!insertmacro InstallLib REGDLL NOTSHARED REBOOT_NOTPROTECTED "LocalPath\ComName.dll" "$SYSDIR\ComName.dll" $SYSDIR
!insertmacro UnInstallLib REGDLL NOTSHARED REBOOT_NOTPROTECTED "$SYSDIR\ComName.dll"
SetRegView 64
!endif
WriteRegStr ...
WriteRegStr ...
SetRegView lastused
!endif
SetRegView鐢ㄦ埛鎵嬪唽錛?/span>
鍦?Windows x64 涓婂叡鏈?縐嶆煡鐪嬫柟寮忋備竴縐嶇敤浜?32-bit 搴旂敤紼嬪簭錛屽彟涓縐嶇敤浜?x64 搴旂敤紼嬪簭銆傞粯璁ゆ儏鍐典笅錛?2-bit 搴旂敤紼嬪簭榪愯鍦?x64 緋葷粺鐨?WOW64 妯″紡涓嬫椂錛屽彧鍏佽浣跨敤 32-bit 鏌ョ湅鏂瑰紡銆備嬌鐢?SetRegView 64 灝嗗厑璁稿畨瑁呯▼搴忓湪 x64 涓闂敞鍐岃〃閿箋?
DeleteRegKey,
DeleteRegValue,
EnumRegKey,
EnumRegValue,
ReadRegDWORD,
ReadRegStr,
WriteRegBin,
WriteRegDWORD,
WriteRegStr,
WriteRegExpandStr銆?/span>SetRegView 32
ReadRegStr $0 HKLM Software\Microsoft\Windows\CurrentVersion ProgramFilesDir
DetailPrint $0 # prints C:\Program Files (x86)
SetRegView 64
ReadRegStr $0 HKLM Software\Microsoft\Windows\CurrentVersion ProgramFilesDir
DetailPrint $0 # prints C:\Program Files
Function .onInit
SetRegView 64
ReadRegStr $INSTDIR HKLM Software\NSIS ""
SetRegView 32
FunctionEnd
!ifdef LIBRARY_X64
${DisableX64FSRedirection}
!endif
!ifdef LIBRARY_X64
!define PROGRAM_FILES_MAP $PROGRAMFILES64
!else
!define PROGRAM_FILES_MAP $PROGRAMFILES
!endif
浠ュ悗鐩存帴鐢?${PROGRAM_FILES_MAP} 浠f浛 $PROGRAMFILES銆?/span>
!macro TIP_WHEN_AMD64_INSTALLER_RUNAT_X86
!ifdef LIBRARY_X64
${If} ${RunningX64}
${else}
MessageBox MB_OK|MB_ICONINFORMATION "璇峰湪64浣嶆搷浣滅郴緇熶笅榪愯銆?
Abort
${EndIf}
!endif
!macroend
!insertmacro TIP_WHEN_AMD64_INSTALLER_RUNAT_X86
SetShellVarContext all ;瀹夎鍒版墍鏈夌敤鎴蜂笅錛宑urrent 琛ㄧず瀹夎鍒板綋鍓嶇敤鎴蜂笅, all 琛ㄧず鎵鏈夌敤鎴蜂笅銆?/span>
FunctionEnd
!insertmacro TIP_WHEN_AMD64_INSTALLER_RUNAT_X86
SetShellVarContext all
FunctionEnd
rem "璁板緱瑕佹妸瀹夎鑴氭湰涓殑 !define LIBRARY_X64 娉ㄩ噴鎺夛紝鍚﹀垯涓嶈兘鐢熸垚32浣嶅畨瑁呭寘銆?
makensis .\myinstaller.nsi
makensis /DLIBRARY_X64 .\myinstaller.nsi
pause
]]>