安裝應用程序,我想這個cmd命令轉換爲VB腳本或PowerShell的使用VBScript
c:\windows\system32\certutil.exe -f -addstore "TrustedPublisher" "Mycert.cer"
我的問題是創建 「TrustedPublisher」 「Mycert.cer」 之間的空間
感謝
安裝應用程序,我想這個cmd命令轉換爲VB腳本或PowerShell的使用VBScript
c:\windows\system32\certutil.exe -f -addstore "TrustedPublisher" "Mycert.cer"
我的問題是創建 「TrustedPublisher」 「Mycert.cer」 之間的空間
感謝
在vbscript字符串中用引號括起來。要將報價放在字符串中,請爲每個報價使用""
。
"""c:\windows\system32\wordpad"" ""c:\windows\win.ini"""
意味着字符串包含
"c:\windows\system32\wordpad" "c:\windows\win.ini"
使用
在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"
你也可以嘗試這樣的代碼:
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
'**************************************************************************
更有意義,你的代碼,如果你的函數的最後一個報價,你後添加一個空格修剪字符串。 – Trigger