Reputation: 11
I would like to convert this cmd command to vb script or powershell
c:\windows\system32\certutil.exe -f -addstore "TrustedPublisher" "Mycert.cer"
My problem is creating the space between "TrustedPublisher" "Mycert.cer"
Thanks
Upvotes: 0
Views: 1207
Reputation: 18827
You can try also like this code :
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
'**************************************************************************
Upvotes: -1
Reputation: 38745
Use
to build your commandline in a structured way. In code:
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
output:
cscript 29649158.vbs
"c:\windows\system32\certutil.exe" -f -addstore "TrustedPublisher" "Mycert.cer"
Upvotes: 2
Reputation: 114
In vbscript strings are enclosed in quotes. To put quotes in a string use ""
for each quote.
"""c:\windows\system32\wordpad"" ""c:\windows\win.ini"""
means the string contains
"c:\windows\system32\wordpad" "c:\windows\win.ini"
Upvotes: 2