Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7877513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:23:34+00:00 2026-06-03T03:23:34+00:00

Is there a .NET (C#) method or API call that I can use to

  • 0

Is there a .NET (C#) method or API call that I can use to query if a Windows Service is disabled? The relevant MSDN article is here.

I want to avoid querying the registry directly. Below is some of the code that I am using right now (and it works). However I am looking for something more elegant and less invasive.

const String basepathStr = @"System\CurrentControlSet\services\";
String subKeyStr = basepathStr + servicenameStr;

using (RegistryKey key = Registry.LocalMachine.OpenSubKey(subKeyStr))
{
    return (int) key.GetValue("Start");
}

I did find a simliar question but I was hoping for a better answer since the answers are presumably outdated (3 years have passed).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T03:23:37+00:00Added an answer on June 3, 2026 at 3:23 am

    This the most relevant section of the code I decided to use…thanks for the help all!

        StartupState state = StartupState.Unknown;
        try
        {
            PermissionSet fullTrust = new PermissionSet(System.Security.Permissions.PermissionState.Unrestricted);
            fullTrust.Demand();
            string wmiQuery = @"SELECT * FROM Win32_Service WHERE Name='" + servicenameStr + @"'";
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(wmiQuery);
            ManagementObjectCollection results = searcher.Get();
            foreach (ManagementObject service in results)
            {
                if (service["StartMode"].ToString() == "Disabled")
                    state = StartupState.Disabled;
                else
                    state = StartupState.Enabled;
            }
            return state;
        }
        catch (SecurityException se)
        {
            return StartupState.Refused;
        }
        catch (Exception e)
        {
            return StartupState.Error;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is any command line or .NET method that runs a process in the
What encryption method does the .NET FormsAuthentication.Encrypt() method use? There's no mention in the
Is there one method or property in the .NET Framework that tells if an
Using ASP.Net MVC 2, is there any way to use the RedirectToAction() method of
I'm faced with a legacy API that doesn't use .NET events, but rather requires
The case: There is a .net application calling unmanaged C code. Used method for
There was an Html.RadioButtonList extension method in ASP.NET MVC Futures. Has anyone found a
Is there a way to Invoke an overloaded method using reflection in .NET (2.0).
I'm using ASP.NET Membership and noticed there isn't a method in the Roles class
What is the best method for user authorisation/authentication in ASP.NET MVC? I see there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.