简体   繁体   English

我如何从asp.net页运行任何win.exe?

[英]How can i run any win.exe from asp.net page?

How can i run any win.exe from asp.net page? 我如何从asp.net页运行任何win.exe?

this codes me error: The system cannot find the file specified 这为我编码错误: 系统找不到指定的文件

 System.Diagnostics.Process process1 = new System.Diagnostics.Process();

            process1.StartInfo.WorkingDirectory = Request.MapPath(@"C:\");

            process1.StartInfo.FileName = Request.MapPath("WindowsApplication1.exe");
            process1.Start();

Remember that the code you posted there is running on your web server . 请记住,您在此处发布的代码正在Web服务器上运行。 It does not and cannot run on the user's machine. 它不能也不可以在用户的计算机上运行。 That would be a major security issue — significant enough to make the web pretty much useless. 那将是一个主要的安全问题-足够重要,足以使网络变得毫无用处。

If that's your intent, then you just need to make sure that your asp.net account — which normally runs with very restricted permissions for security reasons — has proper permissions, access, and trust to run the requested program. 如果这是您的意图,那么您只需要确保您的asp.net帐户(出于安全原因通常以非常有限的权限运行)具有适当的权限,访问权限和信任关系即可运行所请求的程序。 Otherwise you'll need to do something else. 否则,您需要做其他事情。

You don't need Request.MapPath() for what you are doing, since you are already using a local path. 由于您已经在使用本地路径,因此您无需执行Request.MapPath()即可。 Request.MapPath() is used to translate a app-relative URL (eg "~/test.htm") to a local path (eg "c:\\inetpub\\wwwroot\\myapp\\test.htm"). Request.MapPath()用于将应用程序相对的URL(例如“〜/ test.htm”)转换为本地路径(例如“ c:\\ inetpub \\ wwwroot \\ myapp \\ test.htm”)。

Does the application exist at c:\\WindowsApplication1.exe on the server ? 该应用程序是否存在于服务器上的 c:\\ WindowsApplication1.exe中?

Try this one 试试这个

System.Diagnostics.Process process1 = new System.Diagnostics.Process(); process1.StartInfo.FileName = "C:\\WindowsApplication1.exe";
process1.Start();

In this way application is first being downloaded and than it will run. 这样,首先要下载应用程序,然后它将运行。 I don't think it will run from the server. 我认为它不会从服务器运行。

If you want to run it from the server than better you write application in flash or silverlight/moonlight. 如果您想从服务器上运行它而不是更好,则可以在Flash或Silverlight / moonlight中编写应用程序。

What are you trying to do ? 你想做什么 ?

Is your goal here is to execute that on the clients computer, (You can't do this btw) 您的目标是在客户端计算机上执行该操作(顺便说一句)

If it's just some .exe that you want to execute on your server when a user browses that page (I won't even begin with why this is a bad idea) then you're doing a few silly things. 如果只是当用户浏览该页面时要在服务器上执行的某个.exe(我什至不会以为什么这是个坏主意就不会开始),那么您就在做一些愚蠢的事情。

Theres no need for the Request.MapPath 's around your file names. 不需要在文件名周围使用Request.MapPath

You'll also need to make sure your Webserver Identity Account has permission to access and run the file 您还需要确保您的Web服务器身份帐户具有访问和运行文件的权限。

Request.MapPath takes a relative URL, and returns a local filename (on the server), eg Request.MapPath("test.aspx") might return C:\\inetpub\\wwwroot\\MyApp\\Test.aspx . Request.MapPath采用相对URL,并返回本地文件名(在服务器上),例如Request.MapPath("test.aspx")可能返回C:\\inetpub\\wwwroot\\MyApp\\Test.aspx

So basically your 'web page' will be looking for an application on the server in the same directory as the web page called WindowsApplcation1.exe. 因此,基本上,您的“网页”将在服务器上与该网页位于WindowsApplcation1.exe的目录相同的目录中寻找应用程序。

Finally - if you are expecting this windows application to run on the client this wont work, as it will run the application on the server. 最后-如果您希望Windows应用程序在客户端上运行,那么它将无法正常工作,因为它将在服务器上运行该应用程序。 Automatically running files on the client would not be allowed as this would be a security risk. 不允许在客户端上自动运行文件,因为这将带来安全风险。

I am doing it so: 我这样做是:

    var client = new Client(Int32.Parse(Session["uid"].ToString()));
    var genReceipt = new Process();
    genReceipt.StartInfo.FileName = "Chitanta_unit.exe";
    genReceipt.StartInfo.WorkingDirectory = @"C:\chitanta_unit\";
    genReceipt.StartInfo.Arguments = client.ClientID.ToString();
    genReceipt.Start();
    genReceipt.WaitForExit();
    if (genReceipt.ExitCode == 0)
    {
        Response.Redirect("~/subscriber/ch/" + client.GetChitantaFilename());
    }
    genReceipt.Close();

Client class contains operations with customers. 客户类包含与客户的操作。 "C:\\chitanta_unit\\" path at the server. 服务器上的“ C:\\ chitanta_unit \\”路径。 Server is all mine =) I ran it with clientID argument. 服务器全是我的=)我用clientID参数运行它。 And Chitanta_unit.exe is a ConsoleApplication 而且Chitanta_unit.exe是一个ConsoleApplication

It is working well 运行良好

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM