title: C# Service Status On Remote Machine
body: <p>I'm an expert programmer, so therefore, I don't have a clue as to WTH I'm doing :)</p>
  
  <p>On a serious note; no, I'm not expert by any means. I do have a problem though, and don't know how to fix it. The good thing is, I (think I) know what the problem is, and I'm hoping someone here can help.</p>
  
  <p>Here's the synopsis of the problem. I am creating a form in C# that will do some server and database administration task for me. I have a button that when clicked is supposed to return the service status of "x" service on "y" server. The status is printed on the screen to a textbox.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>     private void button2_Click(object sender, EventArgs e)
      {
          string fs = "Service X Status = ";
          string mr = "Service A Status = ";
          string qp = "Service B Status = ";
          string sp = "Spooler Service Status = ";
          ServiceController fssc = new ServiceController("xService", "yServer");
          ServiceController mrsc = new ServiceController("aService", "yServer");
          ServiceController qpsc = new ServiceController("bService", "yServer");
          ServiceController spsc = new ServiceController("Spooler", "yServer");
  
          try
          {
              txtGtwySts.AppendText(sp + spsc.Status.ToString());
              txtGtwySts.AppendText(Environment.NewLine);
              txtGtwySts.AppendText(fs + fssc.Status.ToString());
              txtGtwySts.AppendText(Environment.NewLine);
              txtGtwySts.AppendText(mr + mrsc.Status.ToString());
              txtGtwySts.AppendText(Environment.NewLine);
              txtGtwySts.AppendText(qp + qpsc.Status.ToString());
          }
          catch (Exception crap)
          {
              string msg = "";
              int i;
              for (i = 0; i &lt; crap.Message.Count(); i++)
              {
                  msg += "Error # " + i + " Message: " + crap.Message + "\n";
  
              }
              MessageBox.Show(msg);
              MessageBox.Show(i.ToString());
          }
      }
  </code></pre>
  
  <p>I get exceptions, basically saying: Cannot Open "Service" on "Server." Since this is a remote server, I'm assuming this is a credential/security problem. I do NOT, however, have any problems with the Spooler service.</p>
  
  <p>My question is...How can I pass userID and password to this server so that it will authenticate or runas so I can check the status of these services, it that is the problem. If someone doesnt think its the problem, then please inform me where I've went wrong :)</p>