Run the windows program (ASP. NET1.1) in ASP. NET)

Source: Internet
Author: User

The following describes how to run windows programs in ASP. NET. Create a new asp.net page Default. aspx, and put a button on it to enter the Default. aspx. cs page and enter the background processing program.

Execute the windows program in ASP. NET Step 1. Call the win32 function ShellExecute.

Add reference using System. Runtime. InteropServices;

Declare a function:

 
 
  1. [DllImport("shell32.dll")]    
  2. 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:

 
 
  1. ShellExecute (IntPtr. Zero,"Open","C: \ windows \ notepad.exe",Null,Null, 1 );
  2. // The file name can be unsuffixed, for example, "c: \ windows \ notepad" 

Program completed

Execute the windows program in ASP. NET Step 2. Use the Process class in. NET Framework

Add reference using System. Diagnostics;

Enter the following code in the click event handler of the button:

 
 
  1. Process process =NewProcess ();
  2. Process. StartInfo. FileName ="C: \ windows \ notepad.exe";
  3. // The file name must be suffixed. 
  4. 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 controller, you can even see that the process already exists and the compiler does not report an error), but you cannot see the execution effect, 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 governance, 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 "Agree 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.

Now run the previous program to see the expected result: Execute the windowsprogram notepad.exe in asp.net.

The above programs can run normally in IIS5.0.

  1. ASP. net mvc jQuery Delete Link
  2. Introduce jquery jqrte control in ASP. net mvc Framework
  3. Sample ASP. net mvc project: Suteki. Shop
  4. Example of ASP. net mvc three-tier architecture
  5. The concept of dependency injection in ASP. net mvc Architecture

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.