Passing variable arguments to ShellExecute in vbscript
===

I am trying to learn how to run a vbscript in elevated mode. I can't quite get this to work, if there are arguments to the vbscript I am trying to run elevated.

Here is a simple example:

OSVersion.vbs

    ' Return a string indicating the operating system
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
       & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    Set colOperatingSystems = objWMIService.ExecQuery _
       ("Select * from Win32_OperatingSystem")

    'Wscript.echo Wscript.Arguments(0)
    For Each objOperatingSystem in colOperatingSystems
       Wscript.StdOut.Write objOperatingSystem.Caption
       Wscript.StdOut.WriteBlankLines(1)
       Wscript.StdOut.Write "Version " & objOperatingSystem.Version
    Next

RunElevated.vbs

    ' Run the script in elevated mode
    '
    ' This will be needed to install programs into Program Files
    prgName      = Wscript.Arguments.Item(0)
    prgArgs      = ""
    If Wscript.Arguments.Count > 1 Then
       For i = 1 To Wscript.Arguments.Count - 1
          prgArgs = prgArgs & " " & Wscript.Arguments.Item(i)
       Next
    End If
    Wscript.echo "Running: " & prgName & prgArgs
    Set objShell = CreateObject("Shell.Application")
    Set fso      = CreateObject("Scripting.FileSystemObject")
    strPath      = fso.GetParentFolderName (WScript.ScriptFullName)
    If fso.FileExists(strPath & "\" & prgName) Then
       objShell.ShellExecute "wscript.exe", _
         Chr(34) & strPath & "\" & prgName & Chr(34), _
         "", "runas", 1
    Else
       Wscript.echo "Script file not found"
    End If 

The OSVersion.vbs script runs fine:

> C:\Users\ChemModeling\Documents\FreeThink\Java\install>cscript OSVersion.vbs
> Microsoft (R) Windows Script Host Version 5.8
> Copyright (C) Microsoft Corporation. All rights reserved.
>  
> Microsoft Windows 7 Home Premium
> 
> Version 6.1.7601

Problem #1 When I try to run this elevated, nothing appears on stdout

> C:\Users\ChemModeling\Documents\FreeThink\Java\install>cscript RunElevated.vbs OSVersion.vbs
> Microsoft (R) Windows Script Host Version 5.8
> Copyright (C) Microsoft Corporation. All rights reserved.
> 
> Running: OSVersion.vbs

Problem #2, which is my real problem, as I can get by with no feedback- I cannot figure out how to include and argument to the script I am passing to RunElevated. I read that you should use a syntax like '"my parameters here"' so I tried this:

    ' Run the script in elevated mode
    '
    ' This will be needed to install programs into Program Files
    prgName      = Wscript.Arguments.Item(0)
    prgArgs      = ""
    If Wscript.Arguments.Count > 1 Then
       For i = 1 To Wscript.Arguments.Count - 1
          prgArgs = prgArgs & " " & Wscript.Arguments.Item(i)
       Next
    End If
    Wscript.echo "Running: " & prgName & prgArgs
    Set objShell = CreateObject("Shell.Application")
    Set fso      = CreateObject("Scripting.FileSystemObject")
    strPath      = fso.GetParentFolderName (WScript.ScriptFullName)
    If fso.FileExists(strPath & "\" & prgName) Then
       objShell.ShellExecute "wscript.exe", _
         Chr(39) & Chr(34) & strPath & "\" & prgName & prgArgs & Chr(34) & Chr(39), _
         "", "runas", 1
    Else
       Wscript.echo "Script file not found"
    End If 

If I run:

> cscript RunElevated1.vbs OSVersion.vbs Test
> Microsoft (R) Windows Script Host Version 5.8
> Copyright (C) Microsoft Corporation. All rights reserved.
> 
> Running: OSVersion.vbs Test

I then get an error "There is no engine for file extension ".vbs Test".

Can anyone suggest what I need to change?