在一个。vbs中,我有一些像
Dim sh
Set sh = WScript.CreateObject("WScript.Shell")
'run conf
sh.run "cmd /K php -c php.ini -f some_path'runer'run.php & pause",0,false
'Navigate to the nginx folder to run server
sh.run "cmd /K start nginx & exit", 0, false
Set sh = Nothing
这段代码运行正常。
但是我想在完全执行完sh.run "cmd /K php -c php.ini -f some_path'runer'run.php & pause",0,false
这个命令后再执行sh.run "cmd /K start nginx & exit", 0, false
这个命令,这意味着,在完成run.php
的任务后,我想执行run nginx
。如果可能的话,请回答我。由于
use this,
Dim sh
Set sh = WScript.CreateObject("WScript.Shell")
'run conf
sh.run "cmd /K php -c php.ini -f some_path'runer'run.php & exit",1,true
'Navigate to the nginx folder to run server
sh.run "cmd /K start nginx & exit", 0, false
Set sh = Nothing
这是您的方法的文档。你是在告诉它不要等待。是什么原因让你没去看文档?
在一个新进程中运行一个程序。
object.Run(strCommand, [intWindowStyle], [bWaitOnReturn])
参数对象WshShell对象。
strCommand字符串值,指示要运行的命令行。您必须包含您想要传递给可执行文件的任何参数。
intWindowStyle可选的。指示程序窗口外观的整数值。请注意,并不是所有的程序都使用这些信息。
bWaitOnReturn可选的。布尔值,指示脚本是否应该等待程序完成执行,然后再继续执行脚本中的下一条语句。如果设置为true,脚本执行将停止,直到程序完成,并且Run返回程序返回的任何错误代码。如果设置为false(默认值),Run方法在启动程序后立即返回,并自动返回0(不会被解释为错误代码)。
的评论Run方法返回一个整数。Run方法启动一个在新的Windows进程中运行的程序。您可以让脚本等待程序完成执行后再继续。这允许您同步运行脚本和程序。参数strCommand中的环境变量会自动展开。如果一个文件类型已经被正确地注册到一个特定的程序中,那么在该类型的文件上调用run将执行该程序。例如,如果您的计算机系统上安装了Word,那么在*.doc文件上调用Run将启动Word并加载该文档。下表列出了intWindowStyle的可用设置。
intWindowStyle Description
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.
示例1下面的VBScript代码用记事本打开当前运行脚本的副本。
复制代码
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "%windir%'notepad " & WScript.ScriptFullName
下面的VBScript代码做了同样的事情,除了它指定了窗口类型,等待记事本被用户关闭,并保存从记事本被关闭时返回的错误代码。
复制代码
Set WshShell = WScript.CreateObject("WScript.Shell")
Return = WshShell.Run("notepad " & WScript.ScriptFullName, 1, true)
2的例子下面的VBScript代码打开命令窗口,将路径改为C:',并执行DIR命令。
复制代码
Dim oShell
Set oShell = WScript.CreateObject ("WSCript.shell")
oShell.run "cmd /K CD C:' & Dir"
Set oShell = Nothing
适用于:
试试这个
sh.run "cmd /K php -c php.ini -f some_path'runer'run.php & exit",1,true
对于任何查询,您都可以使用:
Dim sh
Set sh = WScript.CreateObject("WScript.Shell")
sh.run "cmd /K a.exe & exit",1,true
Set sh = Nothing
我想这会对你有帮助。