在 Windows 上以不同用户身份运行 shell_exec

发布于 2024-10-08 09:41:06 字数 533 浏览 0 评论 0原文

我觉得我已经接近答案了,但还没有完全实现。我有一个从 PHP 调用的命令行程序。我使用 shell_exec(),它在运行 Apache 服务器的 Windows 计算机上运行。

当我运行该脚本时,我在 Windows 计算机上的任务管理器中看到该进程已启动,然后立即停止执行任何操作。该进程仍在运行,但它占用了大约 17 MB 的空间,然后 PHP 脚本就在那里加载。

该程序很小 (3MB),可以很好地处理超过该大小的文件,但目前仅处理一个 28 KB 的文件。当我从命令提示符中调用任一者作为“管理员”时,它们工作正常。当我从 shell_exec 调用这个函数时,它没有。我还尝试过 exec() 和 passthru()。

我注意到当PHP调用该程序时,它显示在SYSTEM用户下。我已经检查了程序和程序正在处理的文件的“安全”选项卡上的权限,并且系统、用户和管理员都对它们具有完全控制权。

我做错了什么?

如果我需要以“管理员”身份而不是系统身份运行它,我该怎么做?

如果您有疑问,我可以详细说明。

非常感谢你,这已经害死我了!

I feel like I'm close to the answer, but I'm not quite there. I have a command line program that I call from a PHP. I use shell_exec(), and it runs on a Windows machine running an Apache server.

When I run the script, I see in Task Manager on the Windows machine that the process has started, and then promptly stops doing anything. The process is still running, but it takes up about 17 MB of space and then the PHP script just sits there loading.

The program is tiny (3MB) and it can handle files well over that size, and it's currently only handling one file that's 28 KB. When I call either one from a command prompt as the 'administrator', they work fine. When I call this one from shell_exec, it doesn't. I've also tried exec() and passthru().

I have noticed that when PHP calls the program, it shows up under the SYSTEM user. I've checked permissions on the Security tab of both the program and the file being processed by the program, and SYSTEM, Users, and Administrators all have full control over them.

What am I doing wrong?

If I need to run it as 'administrator' instead of SYSTEM, how do I do that?

I can elaborate more if you have questions.

Thank you so much, this has been killing me!

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

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

发布评论

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

评论(2

梓梦 2024-10-15 09:41:06

请检查PHP配置中的安全模式是否关闭。如果安全模式打开,则只能执行 safe_mode_exec_dir 中的可执行文件。要关闭 safe_mode,请在文本编辑器中打开 php.ini 文件并搜索“safe_mode”。确保它已关闭(即 safe_mode = Off)

另外请尝试其他程序执行函数,例如 system()。请参阅此处
Apache 服务器已作为 httpd.conf 文件中的用户/组设置运行

Please check whether safe mode is off in PHP configuration. If safe mode is on, you can only execute executables within the safe_mode_exec_dir. To make safe_mode off, open php.ini file in a text editor and search for “safe_mode”. Make sure that it is turned off (i.e. safe_mode = Off)

Also please try other Program execution functions such as system(). Refere here
Apache server has run as user/group setting in the httpd.conf file

兰花执着 2024-10-15 09:41:06

我有类似的问题。

我的解决方案是:
只需使用管理员凭据启动 Apache2 服务

I had similar problem.

My solution is:
Just start Apache2 service with administrator's credentials

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