Sunday, February 22, 2009

code for the command line exe

here's the code for the command line exe:

using System;
using System.Windows.Forms;
using System.Diagnostics;

namespace OpenCassini
{
class Program
{
///
/// The main entry point for the application.
///

[STAThread]
static void Main(string[] args)
{
string path;

string command =
@"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\WebDev.WebServer.EXE";
string commandArgs = string.Empty;

Random r = new Random();

string port = r.Next(1024, 9000).ToString();

if(args.Length == 1){
//grab the original path
path = args[0];

commandArgs += " /path:\"" + path + "\"";
commandArgs += " /port:";
commandArgs += port;
commandArgs += " /vpath: \"/";
commandArgs += path.Substring(path.LastIndexOf('\\') + 1);
commandArgs += "\"";

System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();

info.Arguments = commandArgs;
info.CreateNoWindow = true;
info.FileName = command;
info.UseShellExecute = false;
info.WorkingDirectory = command.Substring(0, command.LastIndexOf('\\'));


Process.Start(info);

using(Control c = new Control()){
Help.ShowHelp(c, "http://localhost:" + port + "/");
}
}
}
}
}


Using Help.ShowHelp has the side effect of opening the default browser instead of just IE.

No comments:

Post a Comment