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:
- [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 );
- // 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:
- Process process =NewProcess ();
- 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 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.
- ASP. net mvc jQuery Delete Link
- Introduce jquery jqrte control in ASP. net mvc Framework
- Sample ASP. net mvc project: Suteki. Shop
- Example of ASP. net mvc three-tier architecture
- The concept of dependency injection in ASP. net mvc Architecture