c# - 在iis服务器上从web api运行exe文件不起作用

标签 c# asp.net-web-api

我想在用户请求到来时在 Web API 上执行 exe 文件。它工作完美,但是当我托管 Web API 来服务器时,当用户请求到来时,exe 文件不会执行。如何在 IIS 服务器上从 Web API 执行 exe 文件?

这是进程的起始代码:

public static void Start(long campaign_id, long contact_id, string startDate, string endDate, string user)
{
    try
    {
        //WindowStyle = ProcessWindowStyle.Hidden;
        startInfo.FileName = "cmd.exe";
        startInfo.WorkingDirectory = @"C:\";
        startInfo.Arguments = "/c sparkclr-submit --master " + ConfigurationManager.AppSettings["SparkMaster"] + " --driver-class-path " + AppDomain.CurrentDomain.BaseDirectory + "Engine\\mysql.jar " + "--exe CmAnalyticsEngine.exe " + AppDomain.CurrentDomain.BaseDirectory + "Engine " + campaign_id + " " + contact_id + " " + startDate + " " + endDate + " " + user;
        process.StartInfo = startInfo;
        process.Start();
    }
    catch (Exception e)
    {
        LogWritter.WriteErrorLog(e);
    }
}

最佳答案

你如何启动exe?您有任何错误日志吗?

您可以尝试在 Process.Start 中使用动词 runas 以管理员身份执行 exe 文件。

ProcessStartInfo proc = new ProcessStartInfo();
proc.WindowStyle = ProcessWindowStyle.Normal;
proc.FileName = myExePath;
proc.CreateNoWindow = false;
proc.UseShellExecute = false;
proc.Verb = "runas"; //this is how you pass this verb

关于c# - 在iis服务器上从web api运行exe文件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45139196/

相关文章:

c# - Windows 10 Microsoft Advertising SDK 与 Windows 8.1 兼容吗?

c# - 如何在服务器上使不记名 token 无效

c# - 在运行时禁用 OData V4 元数据和 Controller

c# - 在保持 Web.Config 安全的同时从 WebMethod 获取错误消息

c# - 为什么这个指定的转换无效??

c# - HRESULT : 0x80131040 - Microsoft. WindowsAzure. 未找到存储

c# - 错误处理超过重试次数 10

c# - 引用类库项目中的 System.Diagnostics.Trace

c# - 使用 HttpClient 异步方法返回格式错误的字符串

c# - session 或 webAPI 中的任何替代方案