zoukankan      html  css  js  c++  java
  • 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了!!

    用心写代码,不辜负程序员之名。
  • 相关阅读:
    将Mat类型坐标数据生成pts文件
    DelaunayTriangulation_VoronoiDiagram_using_OpenCV的实现
    安装python第三方库
    安装wordcloud第三方库Unable to find vcvarsall.bat
    Vec3b类型数据确定颜色通道
    使用Inno Setup Compiler制作安装软件包
    QT-This application failed to start because it could not find or load the Qt platform plugin "windows"
    m函数与m文件的命名
    当前目录如何打开cmd
    [Machine Learning & Algorithm] 随机森林(Random Forest)-转载
  • 原文地址:https://www.cnblogs.com/thinkingthigh/p/3076170.html
Copyright © 2011-2022 走看看