Execute an application in Asp.net

Source: Internet
Author: User
Execute an application in Asp.net Program There 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. net Framework process class
Add reference using system. diagnostics;
enter the following Code In the click event handler:
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 obtain the desired result by running the program 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 programs for security reasons. You need to do the following two steps to run properly:
1. Right-click my computer on the desktop and choose manage, expand the "services and applications" node and select "services". Find the "IIS Admin" item in the service list on the right, right-click the item, and select "properties ", open the "login" page in the properties box, select "Allow to interact with desktop" 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.
run the previous program now to view the expected results.
the above programs can run normally in iis5.0.

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.