欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

bat脚本实例实现只允许运行一个实例(安装程序、创建快捷方式脚本)

程序员文章站 2022-06-23 18:44:34
复制代码 代码如下:;我的第一个安装脚本!include "mui2.nsh"!define dir "d:\workspace\nsis\files" name "安装...

复制代码 代码如下:

;我的第一个安装脚本
!include "mui2.nsh"
!define dir "d:\workspace\nsis\files"

name "安装程序"
icon "${dir}\setup128.ico"
outfile "setup.exe"
installdir "$programfiles\kaserv"
requestexecutionlevel admin

!insertmacro mui_page_directory
!insertmacro mui_page_instfiles

!insertmacro mui_language "simpchinese"

function .oninit
 system::call 'kernel32::createmutexa(i 0,i 0,t "smaple_mutex") i .r1 ?e'
 pop $r0
 strcmp $r0 0 +3
 messagebox mb_ok|mb_iconstop "只允许运行一个实例"
 abort
functionend

;安装程序段
section
setoutpath $instdir
file "${dir}\新建文本文档 (2).txt"
file "${dir}\新建文本文档.txt"
setoutpath "$instdir\office"
file "${dir}\office\*"
;快捷方式
createshortcut "$desktop\test.lnk" "$instdir\unsetup.exe"
createshortcut "$smprograms\test.lnk" "$instdir\unsetup.exe"
writeuninstaller "$instdir\unsetup.exe"
sectionend

;卸载程序段
section "uninstall"
rmdir /r "$instdir"
delete "$desktop\test.lnk"
delete "$smprograms\test.lnk"
sectionend