There are two ways to execute an application in asp: 1, call the Win32 function ShellExecute. 2. Use the Process class in the. NET framework. I use these two methods to perform the Notepad program notepad.exe in Windows, respectively.
Create a new ASP. NET page default.aspx, put a button on it and go to the Default.aspx.cs page to fill in the background processing program.
1, call Win32 function ShellExecute.
Add reference using System.Runtime.InteropServices;
Declaring functions:
[DllImport ("Shell32.dll")]
private static extern IntPtr ShellExecute (IntPtr hwnd, String lpoperation, String lpfile, String lpparameters, String lpdi Rectory, Int32 nShowCmd);
In the button's Click event handler, call the ShellExecute function that was previously born:
ShellExecute (IntPtr.Zero, "open", "C:\\windows\\notepad.exe", NULL, NULL, 1);
The file name can be no suffix, such as "C:\\windows\\notepad".
Program completion
2. Using the Process class in the. NET Framework
Add reference using System.Diagnostics;
In the button's Click event handler, fill in the following code:
Process process = new process ();
Process. Startinfo.filename = "C:\\windows\\notepad.exe";
The file name must be suffixed.
Process. Start ();
The program is complete.
Note: Programs that run both of these methods in asp.net2.0 can get the results you want. However, in the asp.net1.1 or earlier version can not get the desired results, open Task Manager can even see the process already exists (the compiler did not error), but just do not see the performance, this is for security reasons that Microsoft banned the operation of the program, you need to do the following two steps to normal operation:
1, right click on the desktop "My Computer", select Management, expand the "Services and Applications" node, select the "Services" item; from the list of services on the right, find the "IIS Admin" entry, right click on the mouse, select "Properties", in the Properties box open the "Login" page, check "Local System account" under " Allow interaction with the desktop item, click OK. Restart the service.
2, open the directory "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\CONFIG" in the Machine.config file, find the "ProcessModel" item, Originally this item has a property is Username= "machine", Change Machine to "system", save file, modify complete.
Now run the previous program to see the desired results.
The above program can run normally in IIS5.0.
Open the. exe in ASP.