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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4504616/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 15:50:17  来源:igfitidea点击:

Running shell_exec as a different user on Windows

phpwindowsapacheexec

提问by spanky

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.

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

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.

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

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().

该程序很小 (3MB),它可以很好地处理超过该大小的文件,并且目前只能处理一个 28 KB 的文件。当我从命令提示符中以“管理员”身份调用其中任何一个时,它们都可以正常工作。当我从 shell_exec 调用这个时,它没有。我也试过 exec() 和 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.

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

What am I doing wrong?

我究竟做错了什么?

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

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

I can elaborate more if you have questions.

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

Thank you so much, this has been killing me!

非常感谢,这让我很伤心!

回答by isurusndr

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)

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

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

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

回答by Graveo

I had similar problem.

我有类似的问题。

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

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