Asp.net executes the EXE application, the ultimate solution.

Source: Internet
Author: User

Execute an application in Asp.netProgramThere are two methods: 1. Call the Win32 function ShellExecute. 2. Use the process class in. NET Framework. Next, I will use these two methods to execute the program notepad.exe in windows.

Create an ASP. NET page default. aspx and put a button on it to enter the default. aspx. CS page and enter the background processing program.

1. Call the Win32 function ShellExecute.

Add reference using system. runtime. interopservices;

Declare a function:

[Dllimport ( " Shell32.dll " )]
Private   Static   Extern Intptr ShellExecute (intptr hwnd, String Lpoperation, String Lpfile, String Lpparameters, String Lpdirectory, int32 nshowcmd );

In the click event handler of the button, call the previously generated ShellExecute Function:

ShellExecute (intptr. Zero, " Open " , " C: \ Windows \ notepad.exe " , Null , Null , 1 );

// You can leave a file name without a suffix, for example, "C: \ WINDOWS \ Notepad ".

Program completed

2. Use the process class in. NET Framework

Add reference using system. diagnostics;

Enter the following in the event handler field for the button:Code:

Process =   New Process ();
Process. startinfo. filename =   " C: \ Windows \ notepad.exe " ;

// The file name must be suffixed.
Process. Start ();

The program is completed.

Note: You can run the programs written in the above two methods in ASP. net2.0. However, in ASP. net1.1 or earlier versions cannot get the desired result. When you open the task manager, you can even see that the process already exists (the compiler does not report an error), but the execution effect is not visible, this is why Microsoft banned the running of the Program for security reasons. You need to take the following two steps to run properly:

1. Right-click my computer on the desktop, select Manage, expand the "services and applications" node, and select "services; find the "IIS Admin" item from the service list on the right, right-click the item, select "properties", and open the "login" page in the property box, select "allow desktop interaction" under "Local SYSTEM account" and click "OK. Restart the service.

2. Open the directory "C: \ WINDOWS \ Microsoft. net \ framework \ v1.1.4322 \ config "machine. in the config file, find the "processmodel" item. One of the original attributes of this item is username = "machine", change the machine to "system", save the file, and finish the modification.

Now run the previous program to see the expected results.

The above programs can run normally in iis5.0.

the above is reposted from others' blogs, but it is not described in this document. In win2003 system, the above method can only be used.
you can see the process and cannot execute the program, solution: In the program pool corresponding to the website, click Properties> ID and change "Network Service" to "local system ", in this way, the EXE called in Asp.net is run locally on the server.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.