static int Main(string[] args) { int result = -2; if (SingleApp.IsRunning()) { return(-3); } try { bool add = false; bool remove = false; bool check = true; if (!IsElevated()) { Program.Log("XenUpdater.exe must be run by an elevated administrator account"); return((int)HRESULT.E_ACCESSDENIED); } // check params for config options... foreach (string arg in args) { switch (arg.ToLower()) { case "add": add = true; check = false; break; case "remove": remove = true; check = false; break; case "check": check = true; break; default: throw new ArgumentException(arg); } } if (add && !remove && !check) { using (Tasks tasks = new Tasks()) { tasks.AddTask(); } } if (remove && !add && !check) { using (Tasks tasks = new Tasks()) { tasks.RemoveTask(); } } if (check && !add && !remove) { AutoUpdate auto = new AutoUpdate(); auto.CheckNow(); } result = 0; } catch (UnauthorizedAccessException e) { Program.Log("Exception: " + e.ToString()); result = (int)HRESULT.E_ACCESSDENIED; } catch (FormatException e) { Program.Log("Exception: " + e.ToString()); result = (int)HRESULT.E_INVALIDARG; } catch (Exception e) { Program.Log("Exception: " + e.ToString()); result = -1; // TODO: Return the HRESULT of this exception } return(result); }
static int Main(string[] args) { int result = -2; if (SingleApp.IsRunning()) return -3; try { bool add = false; bool remove = false; bool check = true; if (!IsElevated()) { Program.Log("XenUpdater.exe must be run by an elevated administrator account"); return (int)HRESULT.E_ACCESSDENIED; } // check params for config options... foreach (string arg in args) { switch (arg.ToLower()) { case "add": add = true; check = false; break; case "remove": remove = true; check = false; break; case "check": check = true; break; default: throw new ArgumentException(arg); } } if (add && !remove && !check) { using (Tasks tasks = new Tasks()) { tasks.AddTask(); } } if (remove && !add && !check) { using (Tasks tasks = new Tasks()) { tasks.RemoveTask(); } } if (check && !add && !remove) { AutoUpdate auto = new AutoUpdate(); auto.CheckNow(); } result = 0; } catch (UnauthorizedAccessException e) { Program.Log("Exception: " + e.ToString()); result = (int)HRESULT.E_ACCESSDENIED; } catch (FormatException e) { Program.Log("Exception: " + e.ToString()); result = (int)HRESULT.E_INVALIDARG; } catch (Exception e) { Program.Log("Exception: " + e.ToString()); result = -1; // TODO: Return the HRESULT of this exception } return result; }