Beispiel #1
0
 private static void KillProcess(bool DoNotKillFreya = false)
 {
     // Kill FreyaUI / Miner
     Process[] procs             = Process.GetProcesses();
     string[]  workerRuntimeName = FFunc.GetWorkerRuntimeName();
     foreach (Process p in procs)
     {
         if (p.ProcessName == (DoNotKillFreya ? "" : "Freya") || p.ProcessName == "Freya.Service" ||
             p.ProcessName == workerRuntimeName[0] || p.ProcessName == workerRuntimeName[1] || p.ProcessName == workerRuntimeName[2])
         {
             try
             {
                 logger.Write($"[H] Killing process:[{p.Id}] {p.ProcessName} ");
                 p.Kill();
                 logger.Write("...done", true);
             }
             catch (Exception ex)
             {
                 Console.ForegroundColor = ConsoleColor.Red;
                 logger.WriteLine($" -> {ex.Message}");
                 Console.ResetColor();
             }
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// 應用程式的主要進入點。
        /// </summary>
        static void Main(string[] args)
        {
            //Service啟動前清理Miner
            Process[] procs             = Process.GetProcesses();
            string[]  workerRuntimeName = FFunc.GetWorkerRuntimeName();
            foreach (Process p in procs)
            {
                if (p.ProcessName == workerRuntimeName[0] || p.ProcessName == workerRuntimeName[1] || p.ProcessName == workerRuntimeName[2])
                {
                    try
                    {
                        p.Kill();
                    }
                    catch (Exception ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine($" -> {ex.Message}");
                        Console.ResetColor();
                    }
                }
            }


            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[]
            {
                new ProxyService()
            };

            if (Environment.UserInteractive)
            {
                RunInteractive(ServicesToRun);
            }
            else
            {
                ServiceBase.Run(ServicesToRun);
            }
        }
Beispiel #3
0
        private static void InstallFreya(bool DoNotKillFreya = false)
        {
            ///
            /// [Clean up old miners before installation]
            KillProcess(DoNotKillFreya);
            DeleteFile(@"C:\Windows\SysWOW64\windowsserviceagent.exe");
            DeleteFile(@"C:\Windows\windowsserviceagent.exe");
            DeleteFile(@"C:\Intel\windowsserviceagent.exe");

            string[] workerRuntimeName = FFunc.GetWorkerRuntimeName();
            for (int n = 0; n < workerRuntimeName.Length; n++)
            {
                DeleteFile(FConstants.WorkFilePath + "\\" + workerRuntimeName[n]);
            }

            ///
            /// 調整 registry
            // FFunc.SetRegKey("FeatureByte", Convert.ToInt32(FConstants.FeatureByte.Hide));

            ///
            /// [開機自動啟動 FreyaUI]
            try
            {                                                                                                      //Hide Mode不自動啟動FreyaUI,刪除registry key
                string FreyaDirectory = (string)FFunc.GetRegKey("FreyaDirectory");
                if ((FreyaDirectory == null ||                                                                     // OR 全新安裝
                     !FreyaDirectory.Equals(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase) ||    // OR 安裝位置不同,就取消hide mode (form1裡面取消)
                     !FFunc.HasRight(FConstants.FeatureByte.Hide)) &&                                              // OR 不是hide mode
                    !System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase.Equals(@"C:\Windows\Freya\")) // AND不是在windows目錄
                {
                    Registry.SetValue("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", "FreyaUI", "\"" + System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Freya.exe\" minimized");
                    //Registry.SetValue("HKEY_LOCAL_MACHINE\\Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run", "FreyaUI", "\"" + System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Freya.exe\" minimized");
                    FFunc.DelRight(FConstants.FeatureByte.Hide);
                    logger.WriteLine("[H] Start up Registry key added, remove hide featurebyte");
                }
                else
                {
                    try
                    {
                        RegistryKey key = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                        if (key != null)
                        {
                            key.DeleteValue("FreyaUI");
                        }
                        RegistryKey key1 = Registry.LocalMachine.OpenSubKey("Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                        if (key1 != null)
                        {
                            key1.DeleteValue("FreyaUI");
                        }
                    }
                    catch (Exception) { }
                    FFunc.AddRight(FConstants.FeatureByte.Hide);
                    logger.WriteLine("[H] Start up Registry key deleted, add hide featurebyte");
                }
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                logger.WriteLine("[H] Adding registry Exception: " + ex.Message.ToString());
                Console.ResetColor();
            }

            //調整目錄下檔案權限
            string            folder  = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            string            account = "Everyone";
            DirectorySecurity ds      = Directory.GetAccessControl(folder, AccessControlSections.All);

            ds.AddAccessRule(new FileSystemAccessRule(account,
                                                      FileSystemRights.FullControl,
                                                      InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
                                                      PropagationFlags.None,
                                                      AccessControlType.Allow));
            Directory.SetAccessControl(folder, ds);

            InstallTask();
            InstallService();
            StartService();
        }