ASP.net C# 尝试在服务器上运行可执行文件

发布于 2024-11-28 07:52:06 字数 830 浏览 2 评论 0原文

我有这个方法,它通过在我们的服务器上运行 exe 程序来生成许可证:

/// <summary>
/// Generate a new license
/// </summary>
public static void GenerateLicense(string Name, string EmailAddress, Licensing.Types.LicenseType Type, Licensing.Types.ProductTypes Product)
{
    string Params = "\"" + Licensing.Types.LicenseTypeToString(Type) + "\" \""
        + Licensing.Types.ProductTypeToString(Product)
        + "\" \"" + Name + "\" \""
        + EmailAddress + "\"";

    // Start license executable and pass in all the params
    Process.Start(Settings.LicenseExecutableLocation, Params);

}

它不会抛出任何错误,并且显然没有运行该程序(它应该在服务器上生成一些文件)。可执行文件(Settings.LicenseExecutableLocation)的位置是C:\inetpub\wwwroot\licensegen.exe,这是正确的,并且参数也是正确的(我已将它们打印出来)。

我正在运行 IIS7,它根本不会抛出任何错误,我需要在 IIS7 中进行某些更改吗?

I have this method which generates a license by running an exe program on our server:

/// <summary>
/// Generate a new license
/// </summary>
public static void GenerateLicense(string Name, string EmailAddress, Licensing.Types.LicenseType Type, Licensing.Types.ProductTypes Product)
{
    string Params = "\"" + Licensing.Types.LicenseTypeToString(Type) + "\" \""
        + Licensing.Types.ProductTypeToString(Product)
        + "\" \"" + Name + "\" \""
        + EmailAddress + "\"";

    // Start license executable and pass in all the params
    Process.Start(Settings.LicenseExecutableLocation, Params);

}

It's not throwing any errors, and it's not apparently running the program (it should be making some files on the server). The location of the executable (Settings.LicenseExecutableLocation) is C:\inetpub\wwwroot\licensegen.exe which is correct, and the paramaters are also correct (I've printed them out).

I'm running IIS7, it's not throwing any errors at all, do I need to change something in IIS7?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

恬淡成诗 2024-12-05 07:52:06

由于启动进程时没有遇到异常,因此您需要找出它实际上在做什么。我会将你的最后一行更改为

var pLicenseGenerator =  Process.Start(Settings.LicenseExecutableLocation, Params);

然后在等待进程执行其操作几秒钟后在调试会话中调查 pLicenseGenerator 对象的属性。此对象将属于 进程 类,我会特别注意 .ExitCode 属性。在设计良好的控制台应用程序中,如果程序遇到错误(如旧的 DOS %ERRORLEVEL% 变量),这将被设置为非零值。

如果 .ExitCode 没有帮助,我建议转储 .StandardOutput 到网页或文件进行调试。

当我过去遇到类似的问题时,这始终是我格式化进程输入参数的方式的问题。有时,如果参数是长文件路径,则需要特别注意用双引号括起来的方式。

一个简单的步骤是说出您传递给 Process.Start() 的确切路径和参数,然后看看您自己从命令行运行它们时会发生什么。如果它们工作正常,那么这可能是某种与权限相关的问题,正如另一位发帖者推测的那样。

Since you're not getting an exception when launching the process, you need to find out what it is actually doing. I would change your last line to

var pLicenseGenerator =  Process.Start(Settings.LicenseExecutableLocation, Params);

And then investigate the properties of the pLicenseGenerator object in a debug session after waiting a few seconds for the process to do its thing. This object will be of the Process class and I would pay special attention to the .ExitCode property. In a well-designed console application, this will be set to a non-zero value if the program encountered an error (like the old DOS %ERRORLEVEL% variable.)

If .ExitCode doesn't help, I'd recommend dumping .StandardOutput to the web page or to a file for debugging.

When I've run into similar issues in the past, it's always been a problem with the way I formatted the process's input parameters. Sometimes if a parameter is a long file path, you need to pay special attention to the way you wrap it in double-quotes.

One simple step would be to spit out the exact path and parameters you are passing to Process.Start() and then see what happens when you run them yourself from the command line. If they work fine, then it is probably some sort of permission-related issue, as another poster speculated.

会傲 2024-12-05 07:52:06

您可能遇到权限问题。可执行文件是否与 Web 应用程序位于同一目录中?如果没有,您可能需要修改权限或考虑使用模拟。如果它确实位于同一目录中,您应该尝试使用相对路径。您可能还需要抑制控制台对话框 - 我遇到过这方面的问题。

希望这有帮助。

You might be running into a permissions issue. Does the executable reside in the same directory as the web application? If not, you may need to modify permissions or look into using impersonation. If it does reside in the same directory, you should try using a relative path. You may also need to suppress the console dialog - I've experienced problems with that.

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文