Certainly possible. Here's one way of doing it.
First, we determine if the server is running already
- Code: Select all
private static bool IsServerProcessRunning()
{
try
{
foreach(Process p in Process.GetProcesses())
{
if(p.ProcessName.ToLower() == "eyetribe")
return true;
}
}
catch (Exception)
{ }
return false;
}
If the server is not running we locate the executable by the method GetServerExecutablePath() and then start it:
- Code: Select all
private static void StartServerProcess()
{
ProcessStartInfo psi = new ProcessStartInfo();
psi.WindowStyle = ProcessWindowStyle.Minimized;
psi.FileName = GetServerExecutablePath();
if (psi.FileName == string.Empty || File.Exists(psi.FileName) == false)
return;
Process processServer = new Process();
processServer.StartInfo = psi;
processServer.Start();
Thread.Sleep(3000); // wait for it to spin up
}
- Code: Select all
private static string GetServerExecutablePath()
{
// check default paths
const string x86 = "C:\\Program Files (x86)\\EyeTribe\\Server\\EyeTribe.exe";
if (File.Exists(x86))
return x86;
const string x64 = "C:\\Program Files\\EyeTribe\\Server\\EyeTribe.exe";
if (File.Exists(x64))
return x64;
// Still not found, let user select file
OpenFileDialog dlg = new OpenFileDialog();
dlg.DefaultExt = ".exe";
dlg.Title = "Please select the Eye Tribe server executable";
dlg.Filter = "Executable Files (*.exe)|*.exe";
if (dlg.ShowDialog() == true)
return dlg.FileName;
return string.Empty;
}
Hope this helps