Launch Program with Parameters. Execute command line in C#. C++ Program to execute another Program with Command line arguments. Debug: Start external program with arguments #746. Create another C# console app, separate solution, to run the external program. Run other programs from your . NET code / Samples / C#Introduction. Once upon a time, a CP member paid $1. He had no practical use for it, he did this just because everyone else seemed to have done so and he did not want to miss the fun. The provider used Windows XP servers to host . NET web applications. The said CP member was learning the Process class in the . NET framework at the time. He found out that he could upload almost any application and execute it on the server machine using this class. The ASPNET account on the server machine had only limited access rights, but he could have done a lot of things on the server that he should not be allowed to do. Anyway, he lost interest later and cancelled the account with the provider. A . NET library to execute other programs. I have included a . NET DLL with this article that demonstrates the use of the Process class in the . NET framework. This DLL contains one class called Command. Obj with a single public method Run to start another application. You can use multiple instances of Command. Obj to start multiple applications from your code. The applications being started do not have to be . NET applications, however. The help documentation on the Process class is so clear that I feel no need to explain any detail here. What I did in the Command. Obj class is make it easier for users to run another program from their code. All you have to do is create an instance of Command. Obj and call the Run method. Here is the signature of the Run method. Run(string s. File. Path, string s. Args. Input, string s. Working. Dir, int n. Wait. Time); The s. File. Path parameter is the full path of the program you want to run. If you pass null or the empty string, the working directory will be inherited from the parent process. If you pass 0 or a negative value, the internal default value 6. The return value of the Run method is whatever the program wrote to its standard output and/or standard error streams. Note that the Run method will not return until the application it started has terminated. But you can modify the Command. Obj class to do things differently or call the Run method from a separate thread so that your main thread won't be blocked. Here is what will happen when you call the Run method. First, a Process. Start. Info object (see . NET documentation) will be created with the given file path and command line. Then the working directory will be set, the standard output and standard error streams will be redirected. Finally, the program you specified will be started by a Process object and its output and error will be read from separate threads. If the started program does not end within the given time, it will be forcefully terminated; when that happens, the return value of the Run method will contain the string . Typical examples of exceptions include wrong file path, access violation, authentication error, etc. The use of the Command. Obj class is not limited to web applications, there is nothing to prevent you from using it to run a GUI program. Remote. Admin, a sample ASP. NET application. If you are working with multiple servers or workstations like me, it can be annoying that you have to logon to different machines all the time. It would be nice if you can logon to one machine and use the browser to access other machines. Remote. Admin is an ASP. NET application built for this purpose. If you install it on a remote machine, you can do all kinds of things without logon to the remote machine. I typically use it to view logs, upload files, replace a binary module (a . NET DLL, for example), mount a network drive, or make configuration changes for a web application (replace the web. There is only one web form in this ASP. NET application. The picture on the left shows how this form is displayed and used in the browser. When this button is clicked, the cmd. This is equivalent to logon to the server, open a command prompt window, and executing the following commands: d. As you can see, you can place a whole bunch of DOS commands into the . Please note that you need to end DOS commands with a return character. If the remote machine runs . NET applications under the . For security risks associated with this, please read the next section. To install Remote. Admin, do the following: unzip all files into a local folder; run the script file Install. Remote. Admin. vbs. The script will ask you on which website (if there is more than one) you want to run this application. It will also ask you what IP address is allowed to access this application. You can modify the script to allow access from more than one IP address. Unless you are working in a secured environment with trustworthy co- workers, you don't want to let everyone access your machine without limitation. After installation, you access the application from the specified IP address by typing the following URL into the address bar of your browser: http: //My. Remote. Machine/Remote. Web. Admin/Remote. Admin. aspx? Action=Run. If you change Action=Run in the query string to Action=Load, then the form will change its appearance to allow you to upload any file to the remote machine. Security Concerns And Disclaimer. As I said or implied earlier, it is easy for others to use the Remote. Admin application to compromise your server. That is why you are not supposed to install it on critical servers. On the machines you do install it, you are recommended to restrict access to a few trusted IP addresses. Since IP addresses can be faked, you may want to implement further authentication/authorization mechanism. You should never modify the machine. ASP. NET applications run under the.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
January 2017
Categories |