NSIS—程序互斥函数(只能运行一个安装程序,安装时不能卸载)
2012-05-17 09:45
1191 查看
/************************
CheckMutex.nsi
************************/
;NSIS 安装程序与卸载程序互相检查互斥的例子
;编写:zhfi
#定义自己的互斥名称:#
#注意安:装程序不能与卸载程序相同!#
!define MyMutex_Install "MyMutex_Install"
!define MyMutex_UnInstall "MyMutex_UnInstall"
!include "LogicLib.nsh"
;安装程序部分
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
;卸载程序部分
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
CheckMutex.nsi
************************/
;NSIS 安装程序与卸载程序互相检查互斥的例子
;编写:zhfi
#定义自己的互斥名称:#
#注意安:装程序不能与卸载程序相同!#
!define MyMutex_Install "MyMutex_Install"
!define MyMutex_UnInstall "MyMutex_UnInstall"
!include "LogicLib.nsh"
;安装程序部分
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
;卸载程序部分
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
相关文章推荐
- 卸载时候出现: windows installer 程序有问题。此安装需要的dll不能运行 的一个解决方法
- NSIS 卸载、安装检测程序是否在运行
- NSIS打包学习(1) : 安装卸载时检查程序是否正在运行
- NSIS 安装包确保只能有一个安装实例运行
- C# 创建互斥进程(程序只能运行一个实例)
- [转]NSIS:安装、卸载时检查程序是否正在运行
- C语言实现的一个程序只能运行一次,不能重复运行
- NSIS:安装、卸载时检查程序是否正在运行
- NSIS——安装、卸载时检查程序是否正在运行
- NSIS 安装包确保只能有一个安装实例运行
- c# 更改注册表开机启动+mutex(互斥,同一时间同一台电脑只能运行一个程序)
- NSIS安装程序完成后运行某程序或某函数
- ANDROID在命令行下安装卸载运行程序
- centos解决yum安装软件时yum.pid已被锁定,PID为xxxx的另外一个程序正在运行
- 让你的程序只能运行一个实例
- c# 程序只能运行一次(多次运行只能打开同一个程序) 并激活第一个实例,使其获得焦点,并在最前端显示.
- 安装、卸载时判断程序是否在运行
- 为何一个MFC程序会有时能正常运行,有时却不能正常运行呢? (内容是来自我的一个帖子)
- C# 让程序只能运行一个实例
- 我写了一个简单的APP,用到了数据库,在程序中我自动建立了一个数据库,可以在File Explorer中找到,然后我把软件安装到虚拟机可以运行。