【发布时间】:2014-06-13 10:07:30
【问题描述】:
我目前正在编写一个 PowerShell 脚本来停止一些进程,启动一个程序,然后重新启动这些进程。当我将进程输入数组变量以稍后重新启动它们时,就会出现问题。
我的代码:
$direc = "C:\Program Files (x86)\PathTo\Program.exe";
$arguments = "/theseArguments1", "/theseArguments2";
$processesDefined = @();
$processes = "notepad", "explorer";
ForEach ($i in $processes)
{
$processesDefined += get-process -name $i | select-object path;
get-process -name $i | stop-process -force;
}
start-process -filepath $direc -ArgumentList $arguments -NoNewWindow -wait;
ForEach ($i in $processesDefined)
{
start-process -filepath $i;
}
当调试 $processesDefined.Count 显示 2 并且 $processesDefined 按预期显示时,当它开始我得到的进程时:
Start-Process : This command cannot be executed due to the error: The system ca
nnot find the file specified.
At D:\Desktop\Aion.ps1:17 char:18
+ start-process <<<< -FilePath $i;
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOp
erationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.C
ommands.StartProcessCommand
我进行了很多搜索,但找不到任何真正的帮助。对此的任何帮助将不胜感激。谢谢。
$processesDefined 的输出:
[DBG]: PS D:\Desktop>>> $processesDefined
Path
----
C:\Program Files\Windows Media Player\wmpnetwk.exe
C:\Windows\explorer.exe
_____________________________________________________________
【问题讨论】:
-
你能把
$processedDefined的内容放上去吗?我认为这可能是$processesDefined的内容的问题
标签: powershell powershell-2.0 powershell-ise