All pastes #1274785 Raw Edit

Mine

public text v1 · immutable
#1274785 ·published 2008-12-03 09:59 UTC
rendered paste body
enum serviceStartType{Auto=1,Manual=2,Disabled=3};

        static void changeServiceStart(string serviceName,serviceStartType serviceType)
        {
            try
            {
                if (File.Exists(Environment.GetEnvironmentVariable("WINDIR") + "\\System32\\sc.exe")) {
                    Process scriptProcess = new Process();
                    scriptProcess.StartInfo.FileName = "sc.exe";
                    scriptProcess.StartInfo.Arguments = "config " + serviceName + " start= " + serviceType.ToString();
                        //scriptProcess.StartInfo.CreateNoWindow = true;
                        //scriptProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                    scriptProcess.StartInfo.UseShellExecute = false;
                    scriptProcess.StartInfo.ErrorDialog = false;
                        //scriptProcess.StartInfo.RedirectStandardInput = true;
                    scriptProcess.StartInfo.RedirectStandardError = true;
                    scriptProcess.StartInfo.RedirectStandardOutput = true;
                    scriptProcess.Start();
                        //StreamWriter inputWriter = scriptProcess.StandardInput;
                    StreamReader outputReader = scriptProcess.StandardOutput;
                    StreamReader errorReader = scriptProcess.StandardError;
                    scriptProcess.WaitForExit();

                    //Write the output of the service-controller to our console:
                    string scOutput = outputReader.ReadToEnd();
                    string scErrOutput = errorReader.ReadToEnd();

                    if (scOutput!=""){prnText(scOutput);};
                    if (scErrOutput != "") { prnText(scErrOutput); };
                }
                else { prnText("Error the Windows service controller 'sc.exe' cannot be found, operation aborted"); return; }
            }
            catch (Exception e)
            {
                prnText("ERROR: " + e.Message);
            }
        }