简体   繁体   中英

Accessing windows service from web

My windows machine have 172 services going on currently .However when i try to access my windows services through web (Asp.net c#) I am getting only 143 services.And my service is not listed.can any one please suggest a way to run my service from web?thank you.

        string strServiceName = param;
        string lblStatus = "";
        string Status = "Undefined";
        string strStatus = string.Empty;
        System.ServiceProcess.ServiceController[] services = null;
        try
        {
            strStatus = "Undefined";

            services = System.ServiceProcess.ServiceController.GetServices();
            for (int i = 0; i < services.Length; i++)
            {
                if (services[i].ServiceName == strServiceName)
                {
                    strStatus = services[i].Status.ToString();
                    Thread.Sleep(500);
                    break;
                }
            }
        }
        catch (Exception ex)
        {
            lblStatus = ex.Message.ToString();
        }
        Status = strStatus;

The account running your web-sites has no permission showing the status of those 29 missing services.

You can use

sc.exe sdshow serviceName

to show the security descriptor for your service. If you compare the descriptor with one service that your code can see, you should see a difference.

You can alter the security descriptor using

sc.exe sdset serviceName ...

But you need to figure out the security descriptor language first.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM