小编Jam*_*mie的帖子

使用启动过程时禁止打开命令窗口

我正在尝试找到一种方法来让PowerShell在运行可执行文件时不生成命令窗口Start-Process.

如果我直接在脚本中调用可执行文件(例如.\program.exe),则程序运行(带有其参数),输出将返回到PowerShell窗口.

如果我使用Start-Process该程序会生成一个程序运行的命令窗口并返回它的输出.

如果我尝试使用脚本的-NoNewWindow开关Start-Process然后错误说它找不到exe文件.

我更愿意使用Start-Process访问-Wait交换机,因为脚本制作的程序和配置可能需要一些时间单独完成,我不希望以后的命令启动.

此代码在单独的命令窗口中运行可执行文件:

Start-Process DeploymentServer.UI.CommandLine.exe -ArgumentList "download --autoDownloadOn --autoDownloadStartTime $StartTime --autoDownloadEndTime $EndTime" -Wait
Run Code Online (Sandbox Code Playgroud)

此代码在PowerShell控制台中运行exe:

.\DeploymentServer.UI.CommandLine.exe download --autoDownloadOn --autoDownloadStartTime $StartTime --autoDownloadEndTime $EndTime
Run Code Online (Sandbox Code Playgroud)

如果我将-NoNewWindow添加到Start-Process代码中

Start-Process DeploymentServer.UI.CommandLine.exe -ArgumentList "download --autoDownloadOn --autoDownloadStartTime $StartTime --autoDownloadEndTime $EndTime" -Wait -NoNewWindow
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Start-Process : This command cannot be executed due to the error: The system
cannot find the file specifie
At C:\Temp\SOLUS3Installv1.3.ps1:398 char:22
+         Start-Process <<<<  DeploymentServer.UI.CommandLine.exe -ArgumentList "download --autoDownloadStartTime $StartTime …

windows powershell

4
推荐指数
1
解决办法
6901
查看次数

-ArgumentList中的启动过程变量

我想知道是否有更多专业知识的人可以帮助我解决我在使用Variables -ArgumentList时遇到的一个小问题Start-Process.

如果我在不使用的情况下运行Exe Start-Process

.\DeploymentServer.UI.CommandLine.exe register --estNumber $Number --postcode $PostCode --password $Password
Run Code Online (Sandbox Code Playgroud)

一切正常,命令运行,软件注册.

如果我试试

Start-Process .\DeploymentServer.UI.CommandLine.exe -ArgumentList "register --estNumber $Number --postcode $PostCode --password $Password" -Wait -NoNewWindow
Run Code Online (Sandbox Code Playgroud)

要么

$Arguments = "register --estNumber $Number --postcode $PostCode --password $Password"
Start-Process .\DeploymentServer.UI.CommandLine.exe -ArgumentList $Arguments -NoNewWindow -Wait
Run Code Online (Sandbox Code Playgroud)

该命令运行但无法注册,说明它无法与提供的详细信息匹配.所以我假设问题在于传递参数Start-Process,或者-ArgumentList解释字符串中的变量.我错过了一些非常简单的东西吗?可能与$在-ArgumentList?

windows powershell

1
推荐指数
1
解决办法
2万
查看次数

标签 统计

powershell ×2

windows ×2