2015-03-03 40 views
0
啓動程序

我已經能夠用下面的代碼之前啓動該程序:試圖在VBScript

dim WshShell 

Set WshShell = WScript.CreateObject("WScript.Shell") 

strCmd = "cmd.exe /c start /D C:\Jts C:\Windows\system32\javaw.exe -cp jts.jar;total.2012.jar -Dsun.java2d.noddraw=true -Dswing.boldMetal=false -Dsun.locale.formatasdefault=true -Xmx768M -XX:MaxPermSize=128M jclient/LoginFrame C:\Jts" 
WshShell.Run(strCmd) 

但是現在,多虧了精彩的java更新,我java.exe文件位於:

C:\Program Files (x86)\Java\jre1.8.0_31\bin\javaw.exe 

我無法替換上述strCmd變量,以便我的VBScript不會出錯。我知道它與Program Files (x86)間距有關,我試圖實現這個答案:How to use spaces in CMD?

但它似乎並沒有工作。請幫忙解釋一下這些空間的用途。

編輯:

我只是想通了。上帝,我討厭空間。顯然,這個工作,我想知道這是不是最好的解決辦法還是沒有:

strCmd = "cmd.exe /c start /D C:\Jts C:\""Program Files (x86)""\Java\jre1.8.0_31\bin\javaw.exe -cp jts.jar;total.2012.jar -Dsun.java2d.noddraw=true -Dswing.boldMetal=false -Dsun.locale.formatasdefault=true -Xmx768M -XX:MaxPermSize=128M jclient/LoginFrame C:\Jts" 
+0

雙引號的整個路徑,不僅是它的一部分。比照http://stackoverflow.com/a/17284837/603855或http://stackoverflow.com/a/14360807/603855 – 2015-03-03 10:47:47

回答

1

第一組的引號內的啓動命令參數假定爲窗口標題。

你的命令不起作用,它可能會出現,但是那是因爲它是如此錯誤的Windows不能告訴多麼錯誤,並把它當作一個部分路徑..

javaw進程將根據應用程序的路徑被列出。您將文件夾指定爲窗口標題,將程序名稱隔離(但Windows知道如何僅通過名稱查找GUI程序)。

暗淡的WshShell

Set WshShell = WScript.CreateObject("WScript.Shell") 

WshShell.Run "cmd.exe /c start """" /D C:\Jts ""C:\Windows\system32\javaw.exe"" -cp jts.jar;total.2012.jar -Dsun.java2d.noddraw=true -Dswing.boldMetal=false -Dsun.locale.formatasdefault=true -Xmx768M -XX:MaxPermSize=128M jclient/LoginFrame C:\Jts" 
  • 固定不必要的混淆和無意義變量產生。

  • 從運行中刪除括號(您沒有測試返回值)。

  • 放在爲Windows標題一組空引號( 「」 「」)

  • 引用javaw進程路徑(並不需要它System32下)。請記住,如果在任何地方使用報價 開始第一組必須是窗口標題。