NSIS 程序互斥函数
文章转自王牌软件
站长推荐:NSetup一键部署软件
一键式完成美化安装包制作,自动增量升级,数据统计,数字签名。应对各种复杂场景,脚本模块化拆分,常规复杂的脚本代码,图形化设置。无需专业的研发经验,轻松完成项目部署。(www.nsetup.cn)
只回答业务咨询
站长推荐:NSetup一键部署软件
一键式完成美化安装包制作,自动增量升级,数据统计,数字签名。应对各种复杂场景,脚本模块化拆分,常规复杂的脚本代码,图形化设置。无需专业的研发经验,轻松完成项目部署。(www.nsetup.cn)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
/************************ CheckMutex.nsi ************************/ ;NSIS 安装程序与卸载程序互相检查互斥的例子 ;编写:zhfi #定义自己的互斥名称:# #注意安:装程序不能与卸载程序相同!# !define MyMutex_Install "MyMutex_Install" !define MyMutex_UnInstall "MyMutex_UnInstall" ;-------------------------------- ;Include Modern UI !include "MUI.nsh" !include "LogicLib.nsh" ;-------------------------------- ;General ;Name and file Name "Mutex Test" OutFile "Mutex.exe" ;-------------------------------- #添加安装页面:# !insertmacro MUI_PAGE_Welcome !insertmacro MUI_PAGE_InstFiles !insertmacro MUI_PAGE_Finish #添加卸载页面:# !insertmacro MUI_UNPAGE_Welcome !insertmacro MUI_UNPAGE_InstFiles !insertmacro MUI_UNPAGE_Finish ;-------------------------------- ;加入语言文件 !insertmacro MUI_LANGUAGE "SimpChinese" ;-------------------------------- ;安装程序部分 Function .onInit InitPluginsDir Call CreateMutex FunctionEnd Function CreateMutex #检查安装互斥:# ReCheck: System::Call 'kernel32::CreateMutexA(i 0, i 0, t "${MyMutex_Install}") i .R1 ?e' Pop $R0 System::Call 'kernel32::CloseHandle(i R1) i.s' #检查卸载互斥:# System::Call 'kernel32::CreateMutexA(i 0, i 0, t "${MyMutex_UnInstall}") i .R3 ?e' Pop $R2 System::Call 'kernel32::CloseHandle(i R3) i.s' #判断安装/卸载互斥的存在# ${If} $R0 != 0 MessageBox MB_RetryCancel|MB_ICONEXCLAMATION "安装程序已经运行!" IdRetry ReCheck Quit ${ElseIf} $R2 != 0 MessageBox MB_RetryCancel|MB_ICONEXCLAMATION "卸载程序已经运行!" IdRetry ReCheck Quit ${Else} #创建安装互斥:# System::Call 'kernel32::CreateMutexA(i 0, i 0, t "${MyMutex_Install}") i .R1 ?e' Pop $R0 StrCmp $R0 0 +2 Quit ${EndIf} FunctionEnd Section Install SetOutPath $EXEDIR WriteUninstaller "$EXEDIR\Uninstall.exe" SectionEnd ;-------------------------------- ;卸载程序部分 Function un.onInit InitPluginsDir Call un.CreateMutex FunctionEnd Function Un.CreateMutex #检查安装互斥:# ReCheck: System::Call 'kernel32::CreateMutexA(i 0, i 0, t "${MyMutex_Install}") i .R1 ?e' Pop $R0 System::Call 'kernel32::CloseHandle(i R1) i.s' #检查卸载互斥:# CheckUnInstall: System::Call 'kernel32::CreateMutexA(i 0, i 0, t "${MyMutex_UnInstall}") i .R3 ?e' Pop $R2 System::Call 'kernel32::CloseHandle(i R3) i.s' #判断安装/卸载互斥的存在# ${If} $R0 != 0 MessageBox MB_RetryCancel|MB_ICONEXCLAMATION "安装程序已经运行!" IdRetry ReCheck Quit ${ElseIf} $R2 != 0 MessageBox MB_RetryCancel|MB_ICONEXCLAMATION "卸载程序已经运行!" IdRetry ReCheck Quit ${Else} #创建卸载互斥:# System::Call 'kernel32::CreateMutexA(i 0, i 0, t "${MyMutex_UnInstall}") i .R1 ?e' Pop $R0 StrCmp $R0 0 +2 Quit ${EndIf} FunctionEnd Section Uninstall SetOutPath $EXEDIR Delete "$EXEDIR\Uninstall.exe" SectionEnd #脚本结束!# |
学习日记,兼职软件设计,软件修改,毕业设计。
本文出自 学习日记,转载时请注明出处及相应链接。
本文永久链接: https://www.softwareace.cn/?p=1424