简体   繁体   English

如果有多个 NSIS 实例,请采取措施

[英]Take action if there are multiple NSIS instances

I am trying to take certain actions based on the number of NSIS instances running.我正在尝试根据正在运行的 NSIS 实例的数量采取某些措施。

If there is only one instance does it perform an action, if there are two or more does it perform another如果只有一个实例,它执行一个动作,如果有两个或更多,它执行另一个

You can check if multiple instances of a process are running and take actions through "if" and "else"?您可以通过“if”和“else”检查一个进程的多个实例是否正在运行并采取措施?

Thank you谢谢

!include LogicLib.nsh
!define INSTALLERMUTEXNAME "TODO: Replace this, your GUID goes here!" ; Get one from guidgen.com

Function .onInit
System::Call 'KERNEL32::CreateMutex(p0, i1, t"${INSTALLERMUTEXNAME}")?e'
Pop $0
${If} $0 = 183 ; ERROR_ALREADY_EXISTS?
  MessageBox MB_OK "Two or more"
${Else}
  MessageBox MB_OK "I'm alone"
${EndIf}
FunctionEnd
Section "REGISTRY"

        !include "Registry.nsh"        
    
    *    !define REGISTRYKEY1 "HKEY_CURRENT_USER\Software\MyApp"        
    *    !define PORTABLEKEY1 "$EXEDIR\User\MyApp.reg"        
    
        ${registry::DeleteKey} "${REGISTRYKEY1}-BackupBy${APPNOSPACE}Portable" $R0    
        Sleep 200                    
    
        ${registry::MoveKey} "${REGISTRYKEY1}" "${REGISTRYKEY1}-BackupBy${APPNOSPACE}Portable" $R0
        Sleep 200                    
    
        ${registry::RestoreKey} "${PORTABLEKEY1}" $R0    
        Sleep 200                        
    
    SectionEnd 


     Section "APPDATA"
    
    *    !define APPDATADIR1 "$APPDATA\MyApp"                
    *    !define PORTABLEDIR1 "$EXEDIR\User\MyApp"    
    
        RMDir "/r" "${APPDATADIR1}-BackupBy${APPNOSPACE}Portable"        
        Rename "${APPDATADIR1}" "${APPDATADIR1}-BackupBy${APPNOSPACE}Portable"    
    
        CreateDirectory "${APPDATADIR1}"                
        CopyFiles /SILENT "${PORTABLEDIR1}\*.*" "${APPDATADIR1}"    
    
    SectionEnd

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM