Samuel Ohwesi
Samuel Ohwesi

Reputation: 11

installing application with vbscript

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

Answers (3)

Hackoo
Hackoo

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

Ekkehard.Horner
Ekkehard.Horner

Reputation: 38745

Use

  1. a function to handle quoting
  2. an array to store the components of the command
  3. Join() to deal with spaces/separators

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

Trigger
Trigger

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

Related Questions