

It seems reasonable to create the instance of the application in the constructor: public NotePad() The location of the application that we want to run could be specified in a number of ways, even as a parameter in the constructor, but in this case a constant is simpler: private const string location = The one of immediate value is Shell, which starts an application running and returns a process handle to it. You should look this up in the documentation because it has lots of useful methods. The object that we want to make use of is Interaction. If you start a new Windows project and add a new class called NotePad then to use the Shell object all we need to do is add a reference (Project,Add Reference) to Microsoft.VisualBasic and add: using Microsoft.VisualBasic However there is nothing stopping C# programmers using classes that were intended to be used in VB. You can start any application using the Process class but VB programmers have the Shell command that is easier to use. The example is a good illustration of not just using the process class, SendKeys and Shell but also how to pass on events and deal with cross-threading problems. EXE program using the Process class, but it is possible to go further and wrap standard Windows applications.Īs a simple example we create a wrapper for NotePad, but the technique works just a well with any Windows application. NET MP3 demonstrates how to run command line. There are lots of techniques for controlling an existing Windows application from code, but why not go one better and write a class that represents the app within your program? It can be done!Īs long as you prepared to use a few non-obvious techniques then running an existing application under the control of a.
