Hello guys, I just started learning C# (having studied VB.NET for the last 2 years) and I was wondering if you could help me out on this problem I have encountered. All I want is start an application using the Process.Start method. In VB.NET, this was pretty easy and straightforward as I needed no "imports" of namespaces (not that I care much about that). Anyway, as far as I'm concerned, this is all the stuff that should be imported (as mentioned in the MSDN article of the method):

using System;
using System.Diagnostics;
using System.ComponentModel;

The funny thing is that after importing System.ComponentModel , it says that ComponentModel does not exist in the System namespace and that I am probably missing an assembly reference of some sort (not really sure what this is). That is only the first part of the problem, though. The other part is that this code will neither work

class MyClass
{
    static void Main()
    {
        Process.Start("IExplore.exe"); // I put IE here as an example only!
    }
}

, because it says that "The name 'Process' does not exist in the current context". Am I missing something? I would really appreciate it if any of you guys explained to me what is wrong here. Thank you in advance.

Recommended Answers

All 6 Replies

Start is not a static method so you have to create a Process object first:

static void Main() {
    Process myProcess = new Process();
    myProcess.Start("IExplore.exe");
}

You'll probably want to play with the StartInfo properties, also

First of all, thank you very much for your help. I cannot seem to make it work, though. While debugging, the following error is thrown: "The type or namespace name 'Process' could not be found (are you missing a using directive or an assembly reference?)"

P.S: I forgot to add this piece of detail. Since I prefer writing code from scratch, I tend to create Empty projects. My guess is that not all required files are referenced or something like that. It must also be noted that, if I create a Console Application and then import System.Diagnostics , it will then work just fine. But what I would like help on is how to solve the problem using an Empty project. Thank you.

You need to reference the system.dll and if you don't want to use using statements you need to use the entire namespace: System.Diagnostics.Process

commented: Exactly what I needed to solve the problem! +2

myProcess.Start does not take any arguments, use StartInfo followed by myProcess.Start();

commented: A piece of some valuable info! +2

I would like to thank both of you for your valuable help! After I referenced System.DLL, it immediately worked!

System.Dll should be one of the first Dll that the deisgner automatically inserts for you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.