I know I had promised in my last post about Cygwin and basically show you how this would work. However due to me not quite getting it just right for you guys I thought I would throw you a little piece of something in the meantime.
C# is also my fave tool for various reasons. Especially the Visual C# Express Edition by Microsoft that has made things easier for almost anyone to code.
The flip side is I now miss using the Borland (Embarcadero) Tools that were around. Microsoft has really taken this RAD methodology far by finally realising that this was how to get people enthusiastic.
Anyway one of the questions that most IT Admin's would love to do is make their jobs easier. If you know programming then it becomes even more easier, however what do you do if you have a tool that does a job and you want to write another tool that you don't want other administrators messing up by accident.
Well sometimes wrapping things in a executable helps. But how do you run an executable that is OS specific in C#?
Well meet System.Diagnostics
It has a class there called Process.
This allows you to define a way of running an external application without finding out a way of writing a interface and things.
So how would this look?
Well people here is a simple example given below that will launch notepad using just a few lines of code.
using System;
using System.Diagnostics;
namespace RunNotepad
{
class Program
{
static void Main(string[] args)
{
using System.Diagnostics;
namespace RunNotepad
{
class Program
{
static void Main(string[] args)
{
// Define an object called p which will create our process.
Process p = new Process();
Process p = new Process();
// Define the application that you want to run. Don't forget to escape the '\' as these are special.
p.StartInfo.FileName = "C:\\windows\\notepad.exe";
p.StartInfo.FileName = "C:\\windows\\notepad.exe";
p.Start();
}
}
}
No comments:
Post a Comment