How can I execute an windows process with C#?
Im gonna create a console application that lets me execute files and stop them
please help out.
Regards
Daemoncraft
Printable View
How can I execute an windows process with C#?
Im gonna create a console application that lets me execute files and stop them
please help out.
Regards
Daemoncraft
Samples in a form load, but it's really the thing (as far as starting a processs).Code:private System.Diagnostics.Process Proc = new System.Diagnostics.Process();
private void Form1_Load(object sender, System.EventArgs e)
{
Proc.StartInfo.FileName = "notepad.exe";
Proc.Start();
}
sevenhalo posted good code, but this one waits for the user to say "exit", and if you want to do it for more than one file, put the entire program in an infinite loop until the user says "quit" for example, and execute files the same way but put processes in an Array or a Generic-List (next time please specify the .NET version you are using)Code:private static System.Diagnostics.Process proc=new System.Diagnostics.Process();
[STAThread()]public static void Main()
{
string Path=Console.ReadLine();
proc.StartInfo.FileName = Path;
proc.Start();
while (Console.ReadLine().ToLower() != "exit") ;
proc.Close();
}
Im creating a console application in C#
I would like to know what files that shutdown the computer..
thought shutdown.exe would do it but it wont:(
Which C# (2002/2003 or 2005)?
And does this code do the trick for you?
2005 version..
well im using that halo guy's script
System.Diagnostics.Process Proc = new System.Diagnostics.Process();
Proc.StartInfo.FileName = "shutdown.exe";
Proc.Start();
but i need to know the file to shutdown the computer.
Code:System.Diagnostics.Process.Start("shutdown.exe","-s");
Quote:
Originally Posted by ComputerJy
Thx man..did think of the use of -s and all that:)
but anyways im having aproblem to use -c
i want it like -c your computer will be shutdown now:)
Shutdown.exe is an executable file that accepts specific commandline arguments. If you want it to behave a specifc way then you have to provide the appropriate arguments. If you want to find out what arguments it accepts and what they mean then open a command prompt and type "shutdown" or "shutdown /?" and it will list them. Alternatively you can read the appropriate topic in Windows Help & Support. So, that's what your app has to do to shut down the system. If you want a user of your app to be able to shut down the system by typing "-c" then you have to use Console.ReadLine to read their input and, if it is "-c" then you need to execute the appropriate code to shut down the system, which you already have.