//connects to remote machine using username, password, and hostname loaded from XML
 private  void ConnectToTargetMachine(Service service)
 {
     String[] serviceDetails = service.ToStringArray();
     //Connect to the remote computer
     ConnectionOptions co = new ConnectionOptions();
     co.Username = serviceDetails[7];
     co.Password = serviceDetails[8];
     //connect to remote machine WMI directory and connection credentials
     //ms = new ManagementScope(@"\\" + serviceDetails[6] + "\\root\\cimv2", co);
     ms = new ManagementScope(@"\\" + this.hostname + "\\root\\cimv2", co);
 }
 private void updateService(Service s)
 {
     ConnectToTargetMachine(s);
     //services.Clear();
     //construct query to select all services
     ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_Service");
     //execute query
     ManagementObjectSearcher searcher = new ManagementObjectSearcher(ms, query);
     //iterate over results
     foreach (ManagementObject o in searcher.Get())
     {
         //if selected service object is equal to passed service name
         if (o["DisplayName"].ToString().Contains(s.Name))
         {
             //set service state
             s.Status = o["State"].ToString();
             //add service to 
             //services.Add(new Service() { DisplayName = o["DisplayName"].ToString(), ServiceName = o["Name"].ToString(), Status = o["State"].ToString(), ServerLocation = hostname });
             currencyManager = (CurrencyManager)metroGrid1.BindingContext[services];
         }
     }
     metroGrid1.DataSource = services;
 }