• WebService 调用服务器上exe应用程序


    最近在一个项目中用到这样的需求,需要PDA通过WebService来启动服务器上的一个exe应用程序,这个exe应用程序是有界面的。当我通过以下代码来启动这个exe时,问题出现了。程序并没有运行,但是在任务管理器里面却可以看到这个exe的进程。

     服务端代码:

        [WebMethod]
        public bool Test()
        {
            try
            {
                Process ProgStock = new Process();
                ProgStock.StartInfo.WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory;  //应用程序所在目录
                ProgStock.StartInfo.UseShellExecute = false;
                ProgStock.StartInfo.RedirectStandardOutput = true;
                ProgStock.StartInfo.CreateNoWindow = true;

                ProgStock.StartInfo.FileName = "WindowsFormsServer.exe";  //执行程序完整路径
                ProgStock.StartInfo.Arguments = "1";   //参数
                ProgStock.Start();

                ProgStock.WaitForExit();

            }
            catch (Exception ex)
            {

                throw ex;
            }
            return true;
        }

    解决的方法:

        在网上了很多方法,一般说aspnet权限不够,需要模拟administrator用户来启动exe,这是其中原因之一,但是仅仅这样还是不行。我试过了这个方法,虽然模拟administrator,在任务管理器里面这个exe的进程用户由aspnet变成了administrator,但是界面还是出不来。

    幸运的是,终于找到了办法。

         修改“服务”。在“我的电脑”,右键“管理” ,选择“IIS Admin”服务,双击,选择“登录”,勾选“服务与桌面交互”

    模拟Administrator用户:

    在“C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG”下面找到machine.config,编辑属性:

     <system.web>
      <processModel autoConfig="true"  userName="Administrator" password="****"/>

    </system.web>

    重启IIS服务就OK了!!

    用心写代码,不辜负程序员之名。
  • 相关阅读:
    userdir 希望用户能够以http://X.X.X.X/~username 方式来访问自己的网页
    var_export() 函数的使用
    mb_detect_encoding — 检测字符的编码
    详解PHP fsockopen的使用方法
    jQuery 返回顶部
    Mysql函数
    sql where 1=1和 0=1 的作用
    Numpy基础学习(三)
    Numpy 中的矩阵
    Numpy数组的全通用函数
  • 原文地址:https://www.cnblogs.com/thinkingthigh/p/3076170.html
Copyright © 2020-2023  润新知