Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: C# Help!  (Read 3234 times)

0 Members and 1 Guest are viewing this topic.

hibyy

    Topic Starter


    Rookie

    • Experience: Familiar
    • OS: Windows 8
    C# Help!
    « on: February 02, 2009, 05:03:06 PM »
    I'm Trying to make a Program that will start another program if you type in the correct password and user name...

    So far I got everything to work except the part where it starts the other program...
    I need some help this is the program so far...

    Code:
    using System;

    public class Password
    {
       public static void Main()
       {   
          Console.WriteLine("Please put in your Username.");
          string U = Console.ReadLine();
          Console.WriteLine("Please put in your Password.");
          string P = Console.ReadLine();
          if (U == "Username")
          {
             if (P == "Password")
             {
    //I don't know what to type here to start another program...
             }
          }
          Console.WriteLine("SUCCESS");
       }
    }

    Bones92



      Hopeful

    • Website Designer and Microcontroller Programmer
    • Thanked: 3
      • PIC Programming New Zealand
    • Computer: Specs
    • Experience: Experienced
    • OS: Windows 7
    Re: C# Help!
    « Reply #1 on: February 03, 2009, 09:24:30 PM »
    Sourced from http://www.csharp-station.com/HowTo/ProcessStart.aspx

    A C# program can launch another program using the Process class.  The Process class is part of the System.Diagnostics namespace.  You start another program by instantiating a Process object, setting members of it's StartInfo property, and invoking it's Start() method.  Listing 1 shows how to start a process from C#.
    Listing 1: Starting a Process: ProcessStart.cs

    Code: [Select]
    using System;
    using System.Diagnostics;

    namespace csharp_station.howto
    {
        /// <summary>
        /// Demonstrates how to start another program from C#
        /// </summary>
        class ProcessStart
        {
            static void Main(string[] args)
            {
                Process notePad = new Process();

                notePad.StartInfo.FileName   = "notepad.exe";
                notePad.StartInfo.Arguments = "ProcessStart.cs";

                notePad.Start();
            }
        }
    }

    Reading further, and applying this to your situation, you don't need the arguments line for your application (unless you are indeed passing it arguments.)

    In the filename, put the full name of your executable, e.g. C:\Myfolder\Program.exe

    Thus, your lines would be
    Code: [Select]
    Process myprogram = new Process();

                myprogram.StartInfo.FileName   = "C:\Myfolder\Program.exe";
               
                myprogram.Start();

    Good Luck

    hibyy

      Topic Starter


      Rookie

      • Experience: Familiar
      • OS: Windows 8
      Re: C# Help!
      « Reply #2 on: February 04, 2009, 11:18:52 AM »
      Thank you ! this helped out A lot!!!!   :)

      Uh Oh I got a Problem

      NVM I Fixed it I for got the

      using System.Diagnostics;


      I put the info in and I got an error Making it.

      Code:
      using System;
      using System.Diagnostics;

      public class Password
      {
         public static void Main(string[] args)
         {   
            Console.WriteLine("Please put in your Username.");
            string U = Console.ReadLine();
            Console.WriteLine("Please put in your Password.");
            string P = Console.ReadLine();
            if (U == "Username")
            {
               if (P == "Password")
               {
                  Process mystuff = new Process();
                  mystuff.StartInfo.FileName = "MyStuff.exe";
                  mysutff.StartInfo.Arguments = "ProcessStart.cs";
                  mystuff.Start();
                  Console.WriteLine("SUCCESS");
               }
            }
         }
      }

      This is the Error

      Error:

      Password.cs(15,5): error CS246: The type or namespace name 'Process' could not be found (are you missing a using directive or an assembly reference?)

      Password.cs(16,5): error CS246: The type or namespace name 'mystuff' could not be found (are you missing a using directive or an assembly reference?)

      Password.cs(17,5): error CS246: The type or namespace name 'mystuff' could not be found (are you missing a using directive or an assembly reference?)

      Password.cs(18,5): error CS246: The type or namespace name 'mystuff' could not be found (are you missing a using directive or an assembly reference?)

      How do I fix this?
      « Last Edit: February 04, 2009, 03:07:12 PM by hibyy »

      Bones92



        Hopeful

      • Website Designer and Microcontroller Programmer
      • Thanked: 3
        • PIC Programming New Zealand
      • Computer: Specs
      • Experience: Experienced
      • OS: Windows 7
      Re: C# Help!
      « Reply #3 on: February 04, 2009, 07:48:03 PM »
      You're very welcome