How to execute the. exe program in Asp.net

Source: Internet
Author: User

I accidentally saw that the. exe application was executed on the webpage.ProgramMethod:

1. Use the process class in. NET Framework

Add referenceUsingSystem. diagnostics;

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

Protected void button#click (Object sender, eventargs E)
{

Process pro = new process ();

Pro. startinfo. filename = "C :\\ WINDOWS \ notepad.exe ";

// Suffix can be omitted for file names

Pro. Start ();

}

The program is completed.

2. Call the Win32 function ShellExecute

Add referenceUsingSystem. 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:

Protected void button#click (Object sender, eventargs E)
{

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

// The file name can be unsuffixed, for example, "C: \ WINDOWS \ Notepad"

}

Program completed

Note:Run the program written in the above two methods in ASP. net2.0 to get the desired result. 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 above iis5.0.

 

If you have any other good solutions, thank you for your suggestions ~

Communicate and learn together ~

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.