Exec vs ExecWait vs ExecShell vs nsExec::Exec vs nsExec::ExecToLog vs nsExec::ExecToStack vs ExecDos

http://stackoverflow.com/questions/11708779/exec-vs-execwait-vs-execshell-vs-nsexecexec-vs-nsexecexectolog-vs-nsexecex



Can I know what are the differences between each Exec, ExecWait, ExecShell, nsExec::Exec, nsExec::ExecToLog, nsExec::ExecToStack, ExecDos and ExecCmd, as in when to use which?

I 've posted the various execute calls I know. I am trying to make a comprehensive list, so that it helps future visitors..

  1. Exec: Plainly execute the called string, be it some application, console or file.

  2. ExecWait: Executes like Exec but waits till the process exits.

  3. ExecShellWhat is it for?

  4. nsExec::Exec: Just like Exec or ExecWait but only for command prompt and that too without opening the console window. I am unsure if it waits for process to exit. Does nsExec::Exec wait for child process to exit?

  5. nsExec::ExecToLogThe documentation says ExecToLog is similar to plain nsExec but it outputs to log window. What does that mean, what is a log window?

  6. nsExec::ExecToStack: The documentation says ExecToStack is similar to plain nsExec but it pushes output to stack. I get that.

  7. ExecDos: Same as nsExec::ExecToStack but it additionally (Is it not?)

    a. takes string parameter that serves as stdin for running application.

    b. works in both sync/async mode.

    c. it works out of section - for .onInit check outs.

  8. ExecCmd: Same as ExecDos but it doesn't require these

    ExpandEnvStrings $3 %COMSPEC% 
    ExecDos::exec  /C 
    

    parts. Am I correct?

share improve this question
 
1 
You may include Timeout::ExecTimeout too, for those who need to kill child process if it takes too long to complete. –   Francisco R  Oct 24 '13 at 17:28
 
@FranciscoR Feel free to edit the question and add it (along with its purpose). I'm not so knowledgeable about the one you mentioned. –   nawfal  Oct 24 '13 at 18:06
 
Realistically, the explanations for what each command should do belong in an answer, not in the question itself. "Am I correct?" = bad StackOverflow question. I'm tempted to move those bits to an answer, but there's already an answer that moving would invalidate. –   Mooing Duck  May 7 '14 at 0:09 
1 
@MooingDuck the problem is if I ask a question like that it might very well get closed since the question would look too broad and loaded and without research effort. I wanted to show some effort put by myself, at the same time quite complete with explanation for all the execute commands in one place. Of course someone can put them all as one answer, that will be good too. –   nawfal  May 7 '14 at 1:36

1 Answer

up vote 23 down vote accepted

1) 2) 3)

Exec and ExecWait use CreateProcess internally and can only start programs and batch files.

ExecShell uses ShellExecute which means that it can also launch any registered filetype (.txt .chm etc) and URLs. It should also be used if the program you are starting needs to elevate with UAC.

4)

nsExec redirects stdout so a console window is not visible when the child process executes. And yes, it waits.

5)

The log window on the instfiles page.

7)

Yes, both ExecDos and ExecCmd are more advanced versions of nsExec.

8)

Correct

share improve this answer

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
一.环境变量配置 ; 定义系统环境变量的 注册表key值 !define WriteEnvStr_RegKey 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"' ;设置环境变量 Function "regExpandStr" SetOverwrite ifnewer ;设置jdk环境变量 WriteRegExpandStr ${WriteEnvStr_RegKey} "JAVA_HOME" "$INSTDIR\jdk1.8.0_131" ;设置CATALINA_DIR WriteRegExpandStr ${WriteEnvStr_RegKey} "CATALINA_DIR" "$INSTDIR\tomcat\bin" ;设置CATA_LINA WriteRegExpandStr ${WriteEnvStr_RegKey} "CATA_LINA" "$INSTDIR\tomcat" ;设置path ReadRegStr $0 HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path" WriteRegExpandStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path" "$0;C:\windows\system32;$INSTDIR\redis;$INSTDIR\mysql\bin;$INSTDIR\Java\jdk1.8.0_131\bin;" #第一次是使环境变量修改对其他进程有效;刷新环境变量 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000 SetOverwrite on functionend ;注册服务 Function "installService" detailprint "------------------------------------install tomcat Service..." Sleep 2000 SetOutPath "$INSTDIR\tomcat\bin" nsExec::Exec 'cmd /c service install' nsExec::Exec 'cmd /c sc config tomcat8 start= auto' ;设置服务自动开启 detailprint "------------------------------------install tomcat Service success..." detailprint "install mysql Service..." Sleep 2000 SetOutPath "$INSTDIR\mysql\bin" nsExec::Exec 'cmd /c $INSTDIR\mysql\bin\mysqld.exe" -install Mysql --defaults-file="$INSTDIR\\mysql\\my.ini' detailprint "install mysql Service success..." detailprint "------------------------------------install redis Service..." Sleep 2000 SetOutPath "$INSTDIR\redis" nsExec::Exec 'cmd /c redis-server --service-install redis.windows.conf' detailprint "install redis Service success..." functionend ; 启动服务 Function "startService" detailprint "------------------------------------start tomcat..." nsExec::Exec 'cmd /c sc start Tomcat8' detailprint "------------------------------------start tomcat success..." detailprint "------------------------------------start mysql..." nsExec::Exec 'cmd /c sc start mysql' detailprint "------------------------------------start MySQL success..." detailprint "------------------------------------start redis..." ;nsExec::Exec 'cmd /c sc redis-server --service-start --service-name redis' detailprint "------------------------------------start redis success..." functionend ;停止服务 Function "un.stopService" detailprint "正在停止tomcat服务......." nsExec::Exec 'cmd /c sc stop tomcat8' detailprint "停止tomcat服务成功......." detailprint "正在停止mysql服务......." nsExec::Exec 'cmd /c sc stop mysql' detailprint "停止mysql服务成功......." detailprint "正在停止redis服务......." nsExec::Exec 'cmd /c sc redis-server --service-stop --service-name redis' detailprint "停止redis服务成功......." functionend ;删除服务 Function "un.uninstService" detailprint "正在卸载tomcat服务......." nsExec::Exec 'cmd /c sc delete tomcat8' detailprint "卸载tomcat服务成功......." detailprint "正在卸载mysql服务......." nsExec::Exec 'cmd /c sc delete mysql' detailprint "卸载mysql服务成功......." detailprint "正在卸载redis服务......." nsExec::Exec 'cmd /c sc delete redis' detailprint "卸载redis服务成功......." functionend ;清空环境变量 Function "un.emptyRegExpandStr" #删除 系统环境变量JAVA_HOME 和 CATALINA_HOME #卸载的时候必须设置JAVA_HOME 和 CATALINA_HOME两个环境系统变量为空,或者删除这两个系统变量。否则会出现NSIS选择系统变量的错误(NSIS会自动选择之前有值的系统变量,而不是选择当前刚设置的系统变量) detailprint "正在删除相关环境变量......." functionend 二.校验mac地址 #序列号 校验页面 Page custom check_serial_number Var "MacAddress" Function check_serial_number Call .GetMacAddress #MessageBox MB_OK '当前机器Mac地址为:$MacAddress' ${if} $MacAddress == '00-50-56-C0-00-08' ${OrIf} $MacAddress == '00-50-56-C0-00-081' #MessageBox MB_OK '已授权' ${Else} MessageBox MB_OK '未授权,请联系经销商并授权!' ;SendMessage $HWNDPARENT 0x408 3 0 #页面跳转 Call onClickClose ${EndIf} FunctionEnd #获取主机MAC地址 Function .GetMacAddress System::Call Iphlpapi::GetAdaptersInfo(i,*i.r0) System::Alloc $0 Pop $1 System::Call Iphlpapi::GetAdaptersInfo(ir1r2,*ir0)i.r0 StrCmp $0 0 0 finish loop: StrCmp $2 0 finish System::Call '*$2(i.r2,i,&t260;.s,&t132;.s,i.r5)i.r0' ;Unicode版将t改为m IntOp $3 403 + $5 StrCpy $6 "" ${For} $4 404 $3 IntOp $7 $0 + $4 System::Call '*$7(&i1;.r7)' IntFmt $7 "X" $7 StrCpy $6 "$6$7" StrCmp $4 $3 +2 StrCpy $6 "$6-" ${Next} StrCpy $MacAddress $6 Goto loop finish: System::Free $1 FunctionEnd 三.关闭按钮功能 ;点击右上角关闭按钮 Function onClickClose FindProcDLL::FindProc "${PRODUCT_NAME}.exe" Sleep 500 Pop $R0 ${If} $R0 != 0 KillProcDLL::KillProc "${PRODUCT_NAME}.exe" ${EndIf} FunctionEnd
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值