SoftwareSamples #2 – Run an application with C#


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RunNotepad
{
class Program
{
static void Main(string[] args)
{
System.Diagnostics.Process.Start("notepad.exe");
}
}
}

Here is what you should do if you want to open a file in Notepad:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RunNotepad
{
class Program
{
static void Main(string[] args)
{
System.Diagnostics.Process.Start("notepad.exe", "C:/path/filename.txt");
}
}
}

Replace C:\path\filename.txt with the path and name of the file. Also, you would usually do backward-slash in Windows instead of forward slash. However, if you use backward-slash the application will run up a bunch of errors.

You can change the application that is launched. If you had SeaSurf installed at C:\Users\yourusername\Desktop\SeaSurfForWindows.exe, for example, you could launch that.

 

Advertisements

User Input in Windows Console Application – C#


 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace InputTest
{
class Program
{
static void Main(string[] args)
{
System.Console.Write("SOFTWARE TERMS OF USE\nYou can use the SoftwareSamples from Chas for free, for demonstration purposes or to help you with your coding, including for business or professional use. You do not have to give credit to Chas AT ALL, though it would be appreciated.\n");
System.Console.WriteLine("Do you accept the Terms of this software?");
String agree = System.Console.ReadLine();
if (agree == "yes")
{
System.Console.WriteLine("Terms accepted. You may use this software");
}
if (agree == "YES")
{
System.Console.WriteLine("Terms accepted. You may use this software");
}
if (agree == "Y")
{
System.Console.WriteLine("Terms accepted. You may use this software");
}
if (agree == "y")
{
System.Console.WriteLine("Terms accepted. You may use this software");
}
if (agree == "n")
{
System.Console.WriteLine("You did not accept the terms. You may not use this software.");
}
if (agree == "no")
{
System.Console.WriteLine("You did not accept the terms. You may not use this software.");
}
if (agree == "NO")
{
System.Console.WriteLine("You did not accept the terms. You may not use this software.");
}
if (agree == "N")
{
System.Console.WriteLine("You did not accept the terms. You may not use this software.");
}
}
}
}

Hi guys, here is how to use input in a Windows Console Application. In this sample, the user has to type YES, yes, Y or y to get access to the software, and if they type NO, no, N or n they will not get access to the software. There is no “software” that will be installed in this script. This is only for demonstration purposes.