///<summary> /// Try loading an assembly ///</summary> ///<param name="fileName"></param> ///<param name="assembly"></param> ///<returns></returns> public static bool TryLoadAssembly(string fileName, out Assembly assembly) { if (string.IsNullOrEmpty(fileName)) { assembly = null; return(false); } if (!PathHelper.FileExists(fileName)) { assembly = null; return(false); } try { //assembly = Assembly.LoadFile(PathHelper.GetRootedPath(fileName)); assembly = Assembly.LoadFrom(PathHelper.GetLocalPath(fileName)); return(true); } catch (Exception ex) { Logger.Debug("Exception caught and discarded: " + ex.Message + " at AssemblyHelper.TryLoadAssembly"); assembly = null; return(false); } }
///<summary> /// Set application to autorun at Windows startup ///</summary> ///<exception cref="ArgumentException"></exception> ///<exception cref="FileNotFoundException"></exception> public void SetToRun() { if (string.IsNullOrEmpty(ApplicationKey)) { throw new ArgumentException("Application key cannot be empty"); } if (string.IsNullOrEmpty(ApplicationPath)) { throw new ArgumentException("Application path cannot be empty"); } if (!PathHelper.FileExists(ApplicationPath)) { throw new FileNotFoundException("Application path not found"); } Registry.SetValue("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", ApplicationKey, ApplicationPath); }