[Solved] Build path and use in external command


Use the appropriate FileSystemObject methods when handling paths:

Set fso = CreateObject("Scripting.FileSystemObject")

SCRIPT_PATH = fso.GetParentFolderName(WScript.ScriptFullName)
SCRIPT_PATH = fso.BuildPath(SCRIPT_PATH, "Delete_App_Script.ps1")

For using variables inside strings you need to concatenate the variables to the rest of the string, as @Lankymart pointed out. This is also documented in the language tag info.

objShell.Run "RUNAS /user:Domain\User ""powershell " & SCRIPT_PATH & """"

Note also that you should put the path in double quotes in case it contains spaces:

objShell.Run "RUNAS /user:Domain\User ""powershell \""" & SCRIPT_PATH & "\"""""

and you should use the parameter -File, otherwise PowerShell would interpret the script path as a command string, which wouldn’t fail for paths with spaces.

objShell.Run "RUNAS /user:Domain\User ""powershell -File \""" & SCRIPT_PATH & "\"""""

6

solved Build path and use in external command