Results 1 to 9 of 9

Thread: How to execute?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2006
    Posts
    20

    How to execute?

    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

  2. #2
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Re: How to execute?

    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();
    		}
    Samples in a form load, but it's really the thing (as far as starting a processs).

  3. #3
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: How to execute?

    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();
            }
    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)
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jun 2006
    Posts
    20

    Re: How to execute?

    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
    Last edited by Daemoncraft; Aug 17th, 2006 at 03:08 PM.

  5. #5
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: How to execute?

    Which C# (2002/2003 or 2005)?
    And does this code do the trick for you?
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jun 2006
    Posts
    20

    Re: How to execute?

    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.

  7. #7
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: How to execute?

    Code:
    System.Diagnostics.Process.Start("shutdown.exe","-s");
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Jun 2006
    Posts
    20

    Re: How to execute?

    Quote Originally Posted by ComputerJy
    Code:
    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

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to execute?

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width