I recently made a small project on the Windows Server POP3 server, and failed to find the interface even though the network was searched.
Fortunately, winpop.exe, a controller interface, was found at the end, that is, to use the CMD command prompt to interact with the POP3 server.
In this case, the efficiency of using the CMD command is low, and it is quite troublesome to obtain and analyze the returned information. However, this is nothing. The most important thing is: in B/S mode, web pagesProgramDo you have the permission to call cmd?
Call cmd here, of course, not the CMD on the customer's machine, but the CMD on the server, so there is a bit of heart.
I carefully conducted an experiment on my computer, successfully called cmd ON THE ASPX page, executed the ping command, and obtained and analyzed the returned information smoothly.
So I release the test program to the server with confidence, and it is also executed smoothly! CoreCodeAs follows:
Using system. diagnostics; using system. io; // <summary> /// cmd Command Execution Assistant class // </Summary> public class cmdhelper {private process P = NULL; private streamreader reader = NULL; /// <summary> /// run the ping command in cmd /// </Summary> /// <Param name = "cmdstring"> command content </param> // /<returns> command execution result </returns> Public String execute (string response string) {processstartinfo start = new processstartinfo ("cmd.exe"); start. filename = "Ping"; start. arguments = parameter string; start. createnowindow = true; start. redirectstandardoutput = true; start. redirectstandardinput = true; start. useshellexecute = false; start. workingdirectory = "C: \ Windows \ System32"; P = process. start (start); reader = P. standardoutput; string line = ""; string linetemp = ""; // read the returned data row by row and perform some processing to facilitate parsing while (! Reader. endofstream) {linetemp = reader. readline (); // read a row // use the '*' sign to indicate if (linetemp = "") {line + = "*";} else {line + = linetemp;} return line ;}}
However, it was too early to be happy. filename = "ping"; changed to start. filename = "winpop"; that is, when the winpop command is executed, "Access Denied" is returned relentlessly ".
What is access denied? Token permissions are also available. Now we have changed to winpopcommand, And we have rejected it, which means we have no right to use winpop.exe!
What should I do now? First, modify the privilege of winpop.exe, right-click winpop.exe (in the Windows/system32 folder), click Properties> Security tab, add the current user to the user, or refuse to add it to ASP. net user, or refuse. Finally, the user is in a hurry. In addition, the Everyone user is still rejected! It seems that this method does not work.
Let's analyze it calmly. This is definitely caused by permission issues. So what are the restrictions on this permission?
Don't forget that our program runs in IIS, and all the killing powers are controlled by IIS. Is the permission here?
Google it. IIS has permissions. More specifically, you can set permissions for the "application pool" in IIS. Next, let's talk about how to set it.
Find your website from IIS, right-click the application pool, and choose Properties to check which application pool is used, and then find it under the application pool directory, right-click --- [attribute]
Find the [ID] tab, find [pre-defined account], and select "Local System" from the drop-down menu!
In this way, your website can execute cmd commands as you like. In fact, it is not only the command to execute cmd, but also the highest permission!
Note that this changes the application pool permissions. Therefore, all websites using this application pool have high permissions, which is quite risky and requiresExercise caution!!
As a complete solution, you also need to mention a bit.
When you call cmd to execute the command, you can specify the user (the user refers to the System user, that is, the account and password used to log on to the computer). In this way, you can also obtain certain permissions. The Code is as follows:
Using system. diagnostics; using system. io; // <summary> /// cmd Command Execution Assistant class // </Summary> public class cmdhelper {private process P = NULL; private streamreader reader = NULL; /// <summary> /// run the ping command in cmd /// </Summary> /// <Param name = "cmdstring"> command content </param> // /<returns> command execution result </returns> Public String execute (string response string) {processstartinfo start = new processstartinfo ("cmd.exe"); start. filename = "Ping"; start. arguments = parameter string; start. createnowindow = true; start. redirectstandardoutput = true; start. redirectstandardinput = true; start. useshellexecute = false; start. workingdirectory = "C :\\ Windows \ System32"; start. username = "Administrator"; // specify the user // construct the user password. Assuming that the password is 123, a single character must be added to the system. security. securestring Password = new system. security. securestring (); password. appendchar ('1'); pas Sword. appendchar ('2'); password. appendchar ('3'); start. password = password; P = process. start (start); reader = P. standardoutput; string line = ""; string linetemp = ""; // read the returned data row by row and perform some processing to facilitate parsing while (! Reader. endofstream) {linetemp = reader. readline (); // read a row // use the '*' sign to indicate if (linetemp = "") {line + = "*";} else {line + = linetemp;} return line ;}}
However, I failed to test in Windows server2003. As long as a user is specified, the webpage program will be suspended until the response times out. The cause is unknown.