powershell - 如何保持窗口打开:ShellExecuteW(0,0 ,“powershell.exe”, “..” ,“..”,SW_SHOW)?

标签 powershell shellexecute

从另一个程序(metatrader)中,我启动了一个ps脚本来下载一些电子邮件:

 shl = ShellExecuteW(0,0,"powershell.exe", "-file x.ps1","..\\path\\to\\scripts",SW_SHOW);

几周没有任何问题(!)之后,我突然在控制台中看到一些红色错误代码-但是关闭得太快了,返回代码(shl)表示没有错误:shl <= 32。

现在,我尝试使用以下命令启动ShellExecuteW(..)
  shl = ShellExecuteW(0,0,"powershell.exe","..","..",SW_SHOWNOACTIVATE);
  # SW_SHOWNOACTIVATE = 4 
  # 4: Displays a window in its most recent size and position. The active window remains active.

但是控制台又消失了:(

1)我必须输入什么才能使控制台保持打开状态-我需要手动关闭1t才能关闭?
2)如何强制ShellExecuteW(..)将错误消息添加到错误文件?

谢谢,周末愉快,
咕ly

PS:用ShellExecuteW(..)重新启动程序后,它可以再次运行而没有任何错误吗?

最佳答案

我认为问题不是ShellExecute,而是Powershell的调用方式。

试试这个:

shl = ShellExecuteW(0,0,"powershell.exe", "-noexit -file x.ps1","..\\path\\to\\scripts",SW_SHOW);

关于powershell - 如何保持窗口打开:ShellExecuteW(0,0 ,“powershell.exe”, “..” ,“..”,SW_SHOW)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26437529/

相关文章:

asp.net-mvc - 清除 IISExpress 缓存

sql - 将T-SQL文件转换为Powershell脚本

delphi - 使用 shellexecute 命令执行 .reg 文件时如何避免确认消息

c# - 从 C# 执行另一个程序,我是否需要自己从注册表中解析 "command line"?

powershell - 在不中断异步事件处理程序的情况下保持 PowerShell 进程处于事件状态

powershell - F5 BIG-IP Powershell/iControl - 查询节点级别的当前连接

windows - 升级到 WSL 2 时出错 : There are no more endpoints available from the endpoint mapper

url - 如何在C++程序中打开URL

c# - 检测在 C# 中使用 openas_rundll 打开的选定程序

MysqlDump 出现 ShellExecute 错误