Beispiel #1
0
        private static void DeleteExistingService()
        {
            var service = GetInstalledService();

            if (service != null)
            {
                var system32 = CrossPlatform.GetSystemFolderPath();
                var sc       = Path.Combine(system32, "sc.exe");

                Process.Start(new ProcessStartInfo(sc, $"stop {ServiceName}")
                {
                    CreateNoWindow = true, UseShellExecute = false
                })?.WaitForExit();
                Process.Start(new ProcessStartInfo(sc, $"delete {ServiceName}")
                {
                    CreateNoWindow = true, UseShellExecute = false
                })?.WaitForExit();
            }
        }
Beispiel #2
0
        public static string PathToPowerShellExecutable()
        {
            if (powerShellPath != null)
            {
                return(powerShellPath);
            }

            try
            {
                var systemFolder = CrossPlatform.GetSystemFolderPath();
                powerShellPath = Path.Combine(systemFolder, @"WindowsPowershell\v1.0\", EnvPowerShellPath);

                if (!File.Exists(powerShellPath))
                {
                    powerShellPath = EnvPowerShellPath;
                }
            }
            catch (Exception)
            {
                powerShellPath = EnvPowerShellPath;
            }

            return(powerShellPath);
        }