1.

Solve : C# Help!?

Answer»

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");
}
}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 LuckThank 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?You're very welcome



Discussion

No Comment Found