public static string GetServiceStartType(string serviceName) { try { return(Registry.LocalMachine.OpenSubKey("SYSTEM").OpenSubKey("CurrentControlSet").OpenSubKey("Services").OpenSubKey(serviceName, true).GetValue("Start").ToString()); } catch (Exception exception) { LogTextHelper.Error(exception); return(string.Empty); } }
public static bool ChangeServiceStartType(int startType, string serviceName) { try { Registry.LocalMachine.OpenSubKey("SYSTEM").OpenSubKey("CurrentControlSet").OpenSubKey("Services").OpenSubKey(serviceName, true).SetValue("Start", startType); } catch (Exception exception) { LogTextHelper.Error(exception); return(false); } return(true); }
public static void SaveOneInchPic(Image image, Color transColor, float dpi, string path) { try { image = image.Clone() as Image; ((Bitmap)image).SetResolution(dpi, dpi); ImageCodecInfo codecInfo = GetCodecInfo("image/jpeg"); EncoderParameters encoderParams = new EncoderParameters(2); encoderParams.Param[0] = new EncoderParameter(Encoder.Quality, 100); encoderParams.Param[1] = new EncoderParameter(Encoder.ColorDepth, 0x20); image.Save(path, codecInfo, encoderParams); image.Dispose(); } catch (Exception exception) { LogTextHelper.Error(exception); } }
public static bool StartService(string serviceName) { try { ServiceController controller = new ServiceController(serviceName); if (controller.Status == ServiceControllerStatus.Running) { return(true); } TimeSpan timeout = TimeSpan.FromMilliseconds(10000.0); controller.Start(); controller.WaitForStatus(ServiceControllerStatus.Running, timeout); } catch (Exception exception) { LogTextHelper.Error(exception); return(false); } return(true); }
public static void ExecuteCommandSync(object command) { try { ProcessStartInfo info = new ProcessStartInfo("cmd", "/c " + command) { RedirectStandardOutput = true, UseShellExecute = false, CreateNoWindow = true }; Process process = new Process { StartInfo = info }; process.Start(); Console.WriteLine(process.StandardOutput.ReadToEnd()); } catch (Exception exception) { LogTextHelper.Error(exception); } }
public static void ExecuteCommandAsync(string command) { try { new Thread(new ParameterizedThreadStart(DosHelper.ExecuteCommandSync)) { IsBackground = true, Priority = ThreadPriority.AboveNormal }.Start(command); } catch (ThreadStartException exception) { LogTextHelper.Error(exception); } catch (ThreadAbortException exception2) { LogTextHelper.Error(exception2); } catch (Exception exception3) { LogTextHelper.Error(exception3); } }