0

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 Commented Jun 16, 2018 at 20:16

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

WScript is a builtin object (of wscript.exe and cscript.exe).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.