Hi Team,
I have a task where i have to build a windows application and from there i have to get the services status (Start/Stopped) where i have to login remotely to other machines into DataGridView.
I have tried and now i'm able to get the service for my computer. Now how can i get the services from other machine (Where i used to connect remotely from my laptop). On that remote machine, I do have services icon on desktop. When i open that, i do have services for many servers. So can you help me achieving this?
Below is my code for fetching the services from my system:
private void button1_Click(object sender, EventArgs e)
{
ServiceController[] se = ServiceController.GetDevices();
ServiceController[] services = ServiceController.GetServices();
int i = 0;
foreach (ServiceController service in services)
{
dataGridView1.Rows.Add();
service.ServiceName = "ALG"; //Finding the paticular service
dataGridView1.Rows[i].Cells["dgvcServiceName"].Value = Convert.ToString(service.ServiceName);
dataGridView1.Rows[i].Cells["dgvcStatus"].Value = Convert.ToString(service.Status);
dataGridView1.Rows[i].Cells["dgvcDescription"].Value = Convert.ToString(service.DisplayName);
i += 1;
}
What I have tried:
I tried taking the Windows Service form at the time of creating the project but as my requirement should be in windows form, i'm little confused how and where to start?
And i took one winform and created a button and datagridview.
I started coding under button click (As after clicking the button, i want that data to be in my gridview). Below is my code:
private void button1_Click(object sender, EventArgs e)
{
ServiceController[] services = ServiceController.GetServices();
foreach (ServiceController service in services)
{
try
{
if (service.ServiceName == serviceName)
return true;
}
return false;
}
catch(Exception ex)
{
MessageBox.Show("Error");
}
}
But i got the error with retun word.