$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run($cmd, 0, false);
我似乎没有找到这个文件......这两个参数对于WScript来说意味着什么?
编辑
它需要一些设置来启用它?我发现上面的脚本不能正常工作是否设置第二个参数为true
或false
$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run($cmd, 0, false);
我似乎没有找到这个文件......这两个参数对于WScript来说意味着什么?
编辑
它需要一些设置来启用它?我发现上面的脚本不能正常工作是否设置第二个参数为true
或false
请参阅here了解详细信息。 Run
的第二个参数是窗口样式(最小化,最大化等),第三个是在继续之前是否等待程序完成。第一个当然是要运行的程序。
这里复制的信息做出回答自足:
object.Run(strCommand,[intWindowStyle],[bWaitOnReturn])
对象 - WshShell对象。
strCommand - 表示要运行的命令行的字符串值。您必须包含要传递给可执行文件的任何参数。
intWindowStyle - 可选。整数值,表示程序窗口的外观。请注意,并非所有程序都使用此信息。
bWaitOnReturn - 可选。指示脚本是否应该等待程序完成执行,然后继续执行脚本中的下一个语句的布尔值。如果设置为true,脚本执行将暂停,直到程序完成,然后Run返回程序返回的任何错误代码。如果设置为false(默认值),则Run方法在启动程序后立即返回,并自动返回0(不能被解释为错误代码)。
窗口样式是:
0 Hides the window and activates another window. 1 Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the first time. 2 Activates the window and displays it as a minimized window. 3 Activates the window and displays it as a maximized window. 4 Displays a window in its most recent size and position. The active window remains active. 5 Activates the window and displays it in its current size and position. 6 Minimizes the specified window and activates the next top-level window in the Z order. 7 Displays the window as a minimized window. The active window remains active. 8 Displays the window in its current state. The active window remains active. 9 Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window. 10 Sets the show-state based on the state of the program that started the application.
Run(strCommand, [intWindowStyle], [bWaitOnReturn])
的运行方法的完整文档是在这里: http://msdn.microsoft.com/en-us/library/d5fk67ky%28VS.85%29.aspx
从上述参考报价:
strCommand字符串值,表示要运行 命令行。你必须 包含任何你想要传递给可执行文件的参数 。
intWindowStyle可选。整数值 表示 程序窗口的外观。请注意,并非所有 程序都使用此信息。
bWaitOnReturn可选。布尔值 指示脚本是否应该等待程序在执行 之前执行 下一条语句。如果将 设置为true,那么脚本执行将暂停,直到程序完成 ,并且运行返回 程序返回的任何错误代码。如果设置为false(默认为 ),则在启动 程序后立即返回 ,并自动返回0 (不会被解释为错误 代码)。
我很迷惑'隐藏窗口并激活另一个窗口'...这里的两个窗口是指什么? – user198729 2010-03-12 16:29:59
@user,它只是表示您打开的窗口将被隐藏。至于其他窗口被激活,这完全取决于Windows本身。有一个很好的机会,它只会是你的程序运行之前活动的窗口,但我不能保证 - Windows可能会遵循各种奇怪的和奇妙的规则来决定:-)你需要关心的唯一一件事新窗口将被隐藏。 – paxdiablo 2010-03-12 16:33:48
我发现该脚本无法正常工作,无论是将“bWaitOnReturn”设置为“true”还是“false” – user198729 2010-03-12 17:37:40