为什么ExecShell忽略我的show type参数?(Why is ExecShell ignoring my show type arguments?)

系统教程 行业动态 更新时间:2024-06-14 17:00:14
为什么ExecShell忽略我的show type参数?(Why is ExecShell ignoring my show type arguments?)

我试图从NSIS安装程序以静默方式和异步方式执行批处理文件。 我希望它是无声的,以防止用户关闭它,我希望它是异步的,这样安装程序将在批处理文件仍在运行时自动关闭。 想法是批处理文件删除安装程序作为实现自我删除安装程序的一种方式。 但是这个问题是关于批处理文件的执行。

我可以使用nsExec::Exec静默执行批处理文件,并且可以使用Exec异步执行批处理文件。 我试图通过使用ExecShell来执行这两个操作,但它不起作用。 不管我传给它什么,显示类型参数似乎都会被忽略。 要确认这不仅限于批处理文件和SW_HIDE ,我试图打开一个简单的文本文件最小化,我仍然无法做到这一点。

ExecShell "" "path.txt" SW_SHOWMINIMIZED ExecShell "open" "path.txt" SW_SHOWMINIMIZED

这两个选项都可以在正常的非最小化窗口中打开写字板(我的默认设置)。 我试过要求管理员权限和隐藏安装细节,但似乎没有任何工作。 我能做什么?

I'm trying to execute a batch file silently and asynchronously from an NSIS installer. I want it to be silent to prevent the user from closing it and I want it to be asynchronous so that the installer will close automatically while the batch file is still running. The idea is for the batch file to delete the installer as a way of implementing a self-deleting installer. But this question is about the execution of the batch file specifically.

I can execute a batch file silently using nsExec::Exec, and I can execute a batch file asynchronously using Exec. I am trying to do both by using ExecShell but it's not working. The show type argument seems to be ignored no matter what I pass to it. To confirm that this isn't limited to batch files and SW_HIDE, I've tried to open a simple text file minimized and I still can't do it.

ExecShell "" "path.txt" SW_SHOWMINIMIZED ExecShell "open" "path.txt" SW_SHOWMINIMIZED

Both of these options simply open WordPad (my default) in a normal non-minimized window. I've tried requesting admin permissions and hiding install details but nothing seems to work. What can I do?

最满意答案

ExecShell的语法是verb command_line [parameters [showmode]] ,即使您不需要,也不能省略参数参数,如果您执行ExecShell "" "path.txt" SW_SHOWMINIMIZED则SW_SHOWMINIMIZED是提供给“ path.txt”。 正确的语法是ExecShell "" "path.txt" "" SW_SHOWMINIMIZED 。

你可以执行ExecShell "open" "c:\path\batch.bat" "" SW_HIDE但如果有人在默认情况下设置了在其文本编辑器中打开的批处理文件,则可能会中断。 最好强迫翻译:

InitPluginsDir FileOpen $0 "$PluginsDir\batch.bat" w FileWrite $0 "ping localhost$\r$\necho." FileWriteByte $0 7 ; ASCII Bell so we know it is running even if hidden FileWrite $0 "$\r$\n" FileWrite $0 "ping localhost$\r$\n" ; Another ping so ASCII Bell actually makes a sound before the process quits FileClose $0 ExpandEnvStrings $0 %COMSPEC% StrCmp $0 "%COMSPEC%" 0 +2 StrCpy $0 "$SysDir\cmd.exe" ExecShell "" '$0' '/C "$PluginsDir\batch.bat"' SW_HIDE Abort "Done"

The syntax for ExecShell is verb command_line [parameters [showmode]] and you cannot leave out the parameters parameter even if you don't want it, if you do ExecShell "" "path.txt" SW_SHOWMINIMIZED then SW_SHOWMINIMIZED is the parameter given to "path.txt". The correct syntax would be ExecShell "" "path.txt" "" SW_SHOWMINIMIZED.

You can just do ExecShell "open" "c:\path\batch.bat" "" SW_HIDE but that could break if somebody has set batch files to open in their text editor by default. It is better to force the interpreter:

InitPluginsDir FileOpen $0 "$PluginsDir\batch.bat" w FileWrite $0 "ping localhost$\r$\necho." FileWriteByte $0 7 ; ASCII Bell so we know it is running even if hidden FileWrite $0 "$\r$\n" FileWrite $0 "ping localhost$\r$\n" ; Another ping so ASCII Bell actually makes a sound before the process quits FileClose $0 ExpandEnvStrings $0 %COMSPEC% StrCmp $0 "%COMSPEC%" 0 +2 StrCpy $0 "$SysDir\cmd.exe" ExecShell "" '$0' '/C "$PluginsDir\batch.bat"' SW_HIDE Abort "Done"

更多推荐

本文发布于:2023-04-18 00:54:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/35e759ae6eb6d0a5e830fe3336a30b4f.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   show   ExecShell   type   arguments

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!