0

I created an ovpn configuration under windows and I actually wanted it to run a Powershell script after the connection is estabilshed.

The last lines of the ovpn-file are as follows

script-security 3
up test.py

The content of the test.py is very simple and I tried both

a)

#!/usr/bin/env python
print('Hello World')

and b)

#!C:\\Program Files\\Inkscape\\bin\\python.exe
print('Hello World')

I am following the documentation here: https://openvpn.net/vpn-server-resources/explanation-of-client-side-scripting-with-simple-examples/

In all cases I keep getting the following error when executing the config.

2022-05-31 13:58:08 openvpn_execve: CreateProcess test.py failed: Unknown error (errno=193)
2022-05-31 13:58:08 WARNING: Failed running command (--up/--down): external program did not execute -- returned error code -1
2022-05-31 13:58:08 Exiting due to fatal error

Any idea why this keeps happening?

MaxM
  • 625
  • 7
  • 13

1 Answers1

0

Okay I found a solution now but I am everything but not happy with it. So looking for s.o. to provide a better solution.

Apparently there seems to be two issues here.

  • The python or powershell script is not executed at all
  • Admin permissions are required to run the script in question

The first one can be solved by creating a simple batch file "up.bat" and running the powershell script from in there.

The contents of the up.bat file:

 "C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe" -ExecutionPolicy ByPass -File up.ps1

Now the only thing I changed was to say

up up.bat

in my above ovpn-Config.

Now that ran the script but unfortunately not as the superuser which would be required for the commands my PowerShell scripts wants to trigger.

Two overcome that it works to

  • run OpenVPN Gui as Admin in the first place (which must people will forget)
  • have the batch file elevate itself before running the Powershell command

For that to work I simply prepended my up.bat with the code taken from this solution here: https://stackoverflow.com/a/12264592/1518458

Now connecting to the VPN will bring up a windows elevation prompt and once this is confirmed the Powershell script will execute properly.

As I said still looking for a nicer solution :)

MaxM
  • 625
  • 7
  • 13