Home  >  Article  >  Backend Development  >  Summary of using php to run exe program under IIS75

Summary of using php to run exe program under IIS75

WBOY
WBOYOriginal
2016-08-08 09:23:38981browse

花了好几天来研究如何在IIS7.5下使用php运行exe程序,总算有点成效,虽然运行成功了但是限制颇多,比如现在只能运行“纯后台”的程序,直接上传文件形式的图片也失败了(上传照片流可以成功),还有待进一步尝试。

下面简单说一下要注意的事情:

1.      配置网站目录权限,增加IUSR帐户;

2.      配置cmd.exe文件的权限,增加IUSR帐户;

3.      必要的情况下,将IUSR帐户添加到管理员权限(但是这样做安全隐患很大,所以要慎重考虑);

4.      很重要的一点——php使用exec()等函数,只能执行“纯后台”的程序,不然会造成程序卡死的情况;

php代码如下:

 

<?php

   if(!function_exists(&#39;system&#39;))

      die(&#39;system() not enable&#39;);

  $cmd = "opf.exe";

   $a= exec($cmd,$out,$status); 

  print_r($a); 

  print_r($out); 

  print_r($status);

  //$result=system(escapeshellcmd($cmd));

  //print "<br>执行结果".$result;

?>

其中opf.exe的源代码如下:

#include<iostream>

using namespace std;

 

int main(int argc,char*argv[])

{

    FILE* file =fopen("D:\\wwwroot\\a.txt","w");

    fprintf(file,"good morning!");

    fclose(file);

    return 2;

}

 

以上就介绍了在IIS75下使用php运行exe程序的总结,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn