2015-04-15 45 views
0

安裝應用程序,我想這個cmd命令轉換爲VB腳本或PowerShell的使用VBScript

c:\windows\system32\certutil.exe -f -addstore "TrustedPublisher" "Mycert.cer" 

我的問題是創建 「TrustedPublisher」 「Mycert.cer」 之間的空間

感謝

回答

1

在vbscript字符串中用引號括起來。要將報價放在字符串中,請爲每個報價使用""

"""c:\windows\system32\wordpad"" ""c:\windows\win.ini""" 

意味着字符串包含

"c:\windows\system32\wordpad" "c:\windows\win.ini" 
3

使用

  1. 一個函數來處理引述
  2. 一個數組來存儲命令
  3. Join()處理空間的部件/分隔符

structured way中構建您的命令行。在代碼:

Option Explicit 

Function qq(s) : qq = """" & s & """" : End Function 

Dim aParts : aParts = Array(_ 
     qq("c:\windows\system32\certutil.exe") _ 
    , "-f" _ 
    , "-addstore" _ 
    , qq("TrustedPublisher") _ 
    , qq("Mycert.cer") _ 
) 
Dim sCmd : sCmd = Join(aParts) 
WScript.Echo sCmd 

輸出:

cscript 29649158.vbs 
"c:\windows\system32\certutil.exe" -f -addstore "TrustedPublisher" "Mycert.cer" 
0

你也可以嘗試這樣的代碼:

Option Explicit 
Dim MyCmd,Ws 
Set Ws = CreateObject("Wscript.Shell") 
MyCmd = "c:\windows\system32\certutil.exe -f -addstore "& DblQuote("TrustedPublisher") &" "& DblQuote("Mycert.cer") &"" 
MsgBox MyCmd 
ws.run MyCmd 
'************************************************************************** 
'Adding Double quotes into variable 
Function DblQuote(Str) 
    DblQuote = Chr(34) & Str & Chr(34) 
End Function 
'************************************************************************** 
+0

更有意義,你的代碼,如果你的函數的最後一個報價,你後添加一個空格修剪字符串。 – Trigger