Click to See Complete Forum and Search --> : How to execute?
Daemoncraft
Aug 17th, 2006, 09:20 AM
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
sevenhalo
Aug 17th, 2006, 09:29 AM
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();
}
Samples in a form load, but it's really the thing (as far as starting a processs).
ComputerJy
Aug 17th, 2006, 01:01 PM
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();
}
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)
Daemoncraft
Aug 17th, 2006, 02:49 PM
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:(
ComputerJy
Aug 17th, 2006, 03:00 PM
Which C# (2002/2003 or 2005)?
And does this code do the trick for you?
Daemoncraft
Aug 17th, 2006, 03:10 PM
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.
ComputerJy
Aug 17th, 2006, 03:12 PM
System.Diagnostics.Process.Start("shutdown.exe","-s");
Daemoncraft
Aug 17th, 2006, 03:17 PM
System.Diagnostics.Process.Start("shutdown.exe","-s");
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:)
jmcilhinney
Aug 17th, 2006, 05:32 PM
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.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.