none
Check Remote Computer Windows Services RRS feed

  • Question

  • Hi,

    I have a server with MySQL and Windows Services installed on it for my C# WinForm application and I have clients connecting to this server.

    I want to alert the users (clients) if my windows service was stopped for any reason on the server.
     
    Is it possible to check the windows service on the server from the client?

    otherwise, I was thinking to let the windows services to log the last run every hour to MySQL database and when the client connect to the MySQL server on the server and found the service was not running for more than one hour then it will alert them?

    What do you think?


    Thanks,
    Jassim
    Thursday, October 22, 2015 9:06 AM

Answers

  • Hi Jassim,

    >>Is it possible to check the windows service on the server from the client?

    Yes, as far as I know, you can use WMI to do that. Here is some code snippet.

    ConnectionOptions op = new ConnectionOptions();
    op.Username = "Domain\\Domainuser";
    op.Password = "password";
    ManagementScope scope = new ManagementScope(@"\\Servername.Domain\root\cimv2", op);
    scope.Connect();
    ManagementPath path = new ManagementPath("Win32_Service");
    ManagementClass services;
    services = new ManagementClass(scope, path, null);
    
    foreach (ManagementObject service in services.GetInstances())
    {
    
    if (service.GetPropertyValue("State").ToString().ToLower().Equals("running"))
    { // Do something }
    
    }

    Except that, also some third-party useful tool like "SC"  or psservice from pstools does just this.

    For more details, please refer to Detect if Windows Service is running of remote machine [duplicate]

    Have a nice day!

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, October 23, 2015 5:50 AM