blob: bf6aca7d201dcebdfbddc6b4a4c58e5cef629375 [file] [log] [blame] [raw]
using System;
using System.Diagnostics;
using System.Net;
using System.Reflection;
using System.Security.Principal;
using System.Threading;
using System.Windows.Forms;
namespace RemoteView
{
class Program
{
static void Main(string[] args)
{
bool banner = true, help = false, error = false;
int port = 6060;
if (!IsRunningAsAdministrator())
{
ProcessStartInfo processInfo = new ProcessStartInfo(Assembly.GetExecutingAssembly().CodeBase);
processInfo.UseShellExecute = true;
processInfo.Verb = "runas";
processInfo.Arguments = String.Join(" ", args);
try
{
Process.Start(processInfo);
}
catch (Exception)
{
Console.WriteLine("Needs administrator rights.");
}
return;
}
// check if http listener is supported
if (!HttpListener.IsSupported)
{
Console.WriteLine("Windows XP SP2 or Server 2003 is required to use the HttpListener class.");
return;
}
// parse command line params
foreach (string arg in args)
{
if (arg.Equals("-b"))
{
banner = false;
}
else if (arg.Equals("-h"))
{
help = true;
}
else if (arg.StartsWith("-p"))
{
int n;
if (int.TryParse(arg.Substring(2), out n))
{
port = n;
}
else
{
error = true;
}
}
else
{
error = true;
}
}
if (banner)
{
showBanner();
}
if (help)
{
showHelpMessage();
return;
}
if (error)
{
Console.WriteLine("Error in Parameter.");
return;
}
// run server
Server server = new Server();
new Thread(() =>
{
server.start(port);
}).Start();
Thread.Sleep(2000);
if (!server.isRunning())
{
Console.WriteLine("Could not start server... Exiting.");
return;
}
Console.WriteLine("Server running press [c] to stop");
while (server.isRunning() && Console.ReadKey(true).Key != ConsoleKey.C) ;
server.stop();
}
private static void showBanner()
{
Console.WriteLine(Application.ProductName + " - Desktop sharing server" + Environment.NewLine);
}
private static void showHelpMessage()
{
Console.WriteLine("Usage:");
Console.WriteLine("RemoteView [-pN] [-b] [-h]");
Console.WriteLine("\t-p :\tListen on port N;");
Console.WriteLine("\t-b :\tDon't show banner message;");
Console.WriteLine("\t-h :\tThis screen;");
// Console.WriteLine("\t-i :\tInstall as Windows service");
// Console.WriteLine("\t-u :\tUninstall as Windows service");
}
private static bool IsRunningAsAdministrator()
{
return new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
}
}
}