Run a VBScript or PowerShell script?

When I try to set the --run-script-after option to point to either a VBScript (somefile.vbs) or a PowerShell script (somefile.ps1), Duplicati throws the error “The specified executable is not a valid application for this OS platform.”. I believe this might be because, for security reasons, the registry is not set up to allow scripts like this to be directly executed.

Normally, in a case like this, one would essentially call the script from another shell like “cmd.exe somefile.vbs” or “powershell -File somefile.ps1”. But if I set the --run-script-after option to either of these strings, then Duplicati throws the error “The system cannot find the file specified”. After doing a little poking around in the source code, I found that Duplicati initializes a System.Diagnostics.ProcessStartInfo class using “scriptpath”, which is presumably the string given to the --run-script-after option, and that calls the System.Diagnostics.Process.Start() method with this class as an argument. Because the string I provided is not a “scriptpath”, but contains both a script an arguments, it throws the “system cannot find the file specified” error.

Am I correct in that there appears to be no way to either directly call a VBScript or PowerShell script either directly or with arguments?

If so, I would propose modifying the code to allow the “scriptpath” to contain both the script and arguments. The string would be split into two, in which the first part is set to the executable name and the rest of the string would be considered as arguments. Then the process could be started uing System.Diagnostics.ProcessStartInfo(psi, args), where psi = System.Diagnostics.ProcessStartInfo(scriptpath). Some consideration for quoting exectuble paths containing white-space would be required to split the string correctly. Another option would be to just add more Duplicati options such as --run-script-after-arguments. This would probably be cleaner.

By the way, what I am doing now is to create a BAT file that then calls my other scripts. This is really annoying though as it means creating another file I need to manage and makes handling things like exit status and the handling of standard output/error more difficult. Calling the other scripts directly (or allowing arguments so that I could) would make things infinitely simpler.

If anyone has any thoughts about alternative approaches, I would be very interested!

That’s exactly what I would have proposed as a workaround.

In the future perhaps the code could be improved to separate the --run-script-after input into two values – script and parameters – at the first non-quoted space.