运行错误的“ up” Windows下的带有OpenVPN的脚本

发布于 2025-02-03 06:54:09 字数 976 浏览 4 评论 0原文

我在Windows下创建了OVPN配置,实际上我希望它在连接后运行PowerShell脚本。

OVPN文件的最后一行如下:

script-security 3
up test.py

测试的内容非常简单,我尝试了

A)

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

和 b)

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

我在此处关注该文档: https://openvpn.net/vpn-server-resources/explanation-client-side-side-side-scripting-with-simple-examples/

在所有情况下,我在执行配置时都会遇到以下错误。

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

知道为什么这会一直在发生吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南笙 2025-02-10 06:54:09

好吧,我现在找到了一个解决方案,但我全部不满意,但对此不满意。因此,寻找这样的解决方案。

显然,这里似乎有两个问题。

  • 在所有admin权限都不执行python或powershell脚本
  • 以运行脚本,

可以通过创建一个简单的批处理文件“ up.bat”并从其中运行PowerShell脚本来解决第一个脚本。

up.bat文件的内容:

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

up up.bat

现在我更改的唯一一件事就是在上面的OVPN-Config中

。现在运行了脚本,但不幸的是,不是作为超级用户,这是我的powershell脚本想要触发的命令所需的。

两个克服了它

  • 首先运行openVPN GUI作为管理员(必须忘记的人),
  • 在运行PowerShell命令之前将批处理文件提升

为工作,我只是简单地将我的up.bat在此处获取该解决方案的代码: https://stackoverflow.com/a/12264592/1518458

现在连接到VPN将提出一个Windows高程提示,一旦确认了PowerShell脚本将正确执行。

正如我所说,仍在寻找更好的解决方案:)

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 :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文