2014-05-18 83 views
0

在一個.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 nginx的的run.php任務後。請回答我是否有可能。謝謝

回答

4

使用此,

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 
1

這是您的方法的文檔。你告訴它不要等待。某些原因你沒有閱讀文檔?

在新進程中運行程序。

object.Run(strCommand, [intWindowStyle], [bWaitOnReturn]) 

參數 對象 WshShell對象。

strCommand 字符串值,指示您想要運行的命令行。您必須包含要傳遞給可執行文件的任何參數。

intWindowStyle 可選。整數值,表示程序窗口的外觀。請注意,並非所有程序都使用此信息。

bWaitOnReturn 可選。指示腳本是否應該等待程序完成執行,然後繼續執行腳本中的下一個語句的布爾值。如果設置爲true,腳本執行將暫停,直到程序完成,然後Run返回程序返回的任何錯誤代碼。如果設置爲false(默認值),則Run方法在啓動程序後立即返回,並自動返回0(不能被解釋爲錯誤代碼)。

備註 Run方法返回一個整數。 Run方法啓動在新Windows進程中運行的程序。您可以讓腳本在繼續之前等待程序完成執行。這使您可以同步運行腳本和程序。參數strCommand中的環境變量會自動展開。如果某個文件類型已正確註冊到特定程序,則調用該類型文件上的運行將執行該程序。例如,如果Word安裝在您的計算機系統上,調用* .doc文件上的運行將啓動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 

適用於:

1

試試這個

sh.run "cmd /K php -c php.ini -f some_path\runer\run.php & exit",1,true 
1

因爲你可以使用任何查詢:

Dim sh 
Set sh = WScript.CreateObject("WScript.Shell") 
sh.run "cmd /K a.exe & exit",1,true 
Set sh = Nothing 

我認爲這對你有幫助。

相關問題