Check for Scheduled Task Existence and Check state
<p>I am using the following code to change the 'Run As:' username and password for a scheduled task on a remote host.</p>

<pre><code>Process p = new Process();
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.FileName = "SCHTASKS.exe";
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;



            //p.StartInfo.Arguments = String.Format("/Change /TN {0} /RU {1} /RP {2}",ScheduledTaskName,userName,password);
            p.StartInfo.Arguments = String.Format("/Change /S {0} /TN {1} /TR {2} /RU {3}\\{4} /RP {5}", MachineName, ScheduledTaskName, taskPath, activeDirectoryDomainName, userName, password);
            p.Start();
            // Read the error stream first and then wait.
            string error = p.StandardError.ReadToEnd();
            p.WaitForExit();
</code></pre>

<p>I have a couple of questions:</p>

<ol>
<li>How can I check if the specified service exists at all, so that if it does not exist, I can just quit the program.</li>
<li>How can i check to see if the scheduled task is running or disabled?</li>
<li>If the scheduled task is disabled, can I still change the credentials, or is it like a Windows service where credentials cannot be changed if it is disabled?</li>
</ol>
