0
votes

I am trying to run a VBScript which opens a program with elevated privileges and also pass it parameters.

Set oShell = CreateObject("Shell.Application")
Dim path = "app.exe"
If WScript.Arguments.Count = 1 Then
    path = path & WScript.Arguments(0)
End If
oShell.ShellExecute path, , , "runas", 1

I get an error in the 2nd line. I tried using As String but that also didn't work.

Any ideas?

1
Please include the actual error msg, that helps a lot when you ask for help here at SO - David

1 Answers

3
votes

You are not allowed to declare a variable and set a value at the same time. Try this syntax instead.

Dim path
path = "app.exe"

or alternatively:

Dim path : path = "app.exe"

Where is the object WScript coming from? I don't see it initialized.

A great 'feature' to turn on is Option Explicit. When activated you must explicitly declare all variables by using the Dim or ReDim statements. If you try to use an undeclared variable name, an error occurs at compile time. This makes it easier to spot problems.