从PowerShell模块内部启动EXE

时间:2009-12-03 19:59:49

标签: powershell

这从PowerShell控制台运行时,按预期启动Internet Explorer:

$ie_command = "C:\Program Files (x86)\Internet Explorer\iexplore.exe"
&$ie_command

如果我在模块中的函数内放置相同的确切代码,它什么都不做。并且,是的,同一功能中的其他代码可以正常工作,因此不会导致模块无法导入或任何问题。

我错过了什么吗?为什么这不起作用?

1 个答案:

答案 0 :(得分:2)

PS C:\SchedTasks\test> cat test.ps1
$ie_command = "C:\Program Files\Internet Explorer\iexplore.exe"
&$ie_command
PS C:\SchedTasks\test> .\test.ps1
PS C:\SchedTasks\test>

这为我打开了一个浏览器窗口。你做的不同吗?

在任何情况下,启动Internet Explorer的另一种方法是使用COM适配器:

$ie = new-object -com InternetExplorer.Application
$ie.Visible = $True