为什么不能运行的exec()或系统()功能的可执行文件? [英] Why cannot run an executable file with exec() or system() functions?

查看:516
本文介绍了为什么不能运行的exec()或系统()功能的可执行文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图运行记事本服务器上(本地主机现在)。

I'm trying to run notepad on the server (localhost for now).

执行exec()系统()功能,例如写时工作正常平127.0.0.1

exec() and system() functions are working fine when for example write ping 127.0.0.1.

但是,这并不正常工作(工作正常,如果我直接写的命令,在命令提示符):

But this does not work (working fine if I write the command directly in the command prompt):

$command = "C:\WINDOWS\system32\notepad.exe";

$result = system($command);

print_r($result);

使用的Windows XP XAMPP 。大概是因为该命令从其他帐户执行,但我不知道该如何检查我没有权限。

Using Windows XP with xampp. Probably I don't have permissions because the command is executed from some other account but I don't know how to check this.

有何意见?

编辑:

由于 bwoebi 说,我已经打开的进程,但他们从不同的用户(系统)打开,打开应用程序时,我看不到。所以,我套用我的问题:如何改变这是从一个PHP脚本执行命令时使用的用户?

As bwoebi said, I have opened processes but they are opened from a different user (SYSTEM) and I can't see when the application is opened. So, I have to paraphrase my question: how to change the user which is used when executing commands from a PHP script?

推荐答案

首先,你需要躲避反斜杠在命令字符串,如果你不使用单引号:

First you need to escape the backslashes in your command string if you're not using single quotes :

$command = "C:\\WINDOWS\\system32\\notepad.exe";

另外请注意,如果Apache运行作为Windows服务,它没有桌面交互的许可,所以它不能打开一个GUI ,请尝试直接用PHP在命令行中运行脚本

Also note that if Apache is running as a Windows service, it does not have desktop interaction permission, so it can't open a GUI, try running the script directly with PHP on the command line.

修改

用于运行命令的用户是运行PHP的用户。要改变运行PHP的用户,你就必须改变运行Apache用户,如果您希望此用户拥有桌面交互的权限,你必须自己运行Apache,而不是作为一个服务

The user used to run command is the user that is running PHP. To change the user running PHP, you'll have to change the user running Apache, if you want this user to have desktop interaction permission, you'll have to run Apache yourself and not as a service.

这篇关于为什么不能运行的exec()或系统()功能的可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆