Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to count Startup Services and Processes using C#

How to count Startup Services and Processes using C#

Scheduled Pinned Locked Moved C#
csharptutorial
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Neeraj Kr
    wrote on last edited by
    #1

    How to count the number of startup services and processes using C#. Is there a specific Win32 Class for this.

    -----Have A Nice Day-----

    M 1 Reply Last reply
    0
    • N Neeraj Kr

      How to count the number of startup services and processes using C#. Is there a specific Win32 Class for this.

      -----Have A Nice Day-----

      M Offline
      M Offline
      Manas Bhardwaj
      wrote on last edited by
      #2

      RegistryKey theKey = Registry.LocalMachine.OpenSubKey
      @("Software\\Microsoft\\Windows\\CurrentVersion\\Run");
      string[] theValueNamesOfKey = theKey.GetValueNames();

      :)

      N 1 Reply Last reply
      0
      • M Manas Bhardwaj

        RegistryKey theKey = Registry.LocalMachine.OpenSubKey
        @("Software\\Microsoft\\Windows\\CurrentVersion\\Run");
        string[] theValueNamesOfKey = theKey.GetValueNames();

        :)

        N Offline
        N Offline
        Neeraj Kr
        wrote on last edited by
        #3

        Actually I know about this registry key, but when I count the items in the Run Folder it comes out to be lesser than items listed in the startup section of the msconfig.

        -----Have A Nice Day-----

        N M 2 Replies Last reply
        0
        • N Neeraj Kr

          Actually I know about this registry key, but when I count the items in the Run Folder it comes out to be lesser than items listed in the startup section of the msconfig.

          -----Have A Nice Day-----

          N Offline
          N Offline
          Neeraj Kr
          wrote on last edited by
          #4

          I created the following method for finding out the number of all the startup processes which is exclusive of the one in the HKLM\Software\Microsoft\CurrentVersion\Run. Here it goes.

          public int getStartupProcessCount()
          {
          RegistryKey theKeyHKLM = Registry.LocalMachine.OpenSubKey(@"Software\\Microsoft\\Windows\\CurrentVersion\\Run");
          string[] theValueNamesOfKeyHKLM = theKeyHKLM.GetValueNames();
          RegistryKey theKeyHKCU = Registry.CurrentUser.OpenSubKey(@"Software\\Microsoft\\Windows\\CurrentVersion\\Run");
          string[] theValueNamesOfKeyHKCU = theKeyHKCU.GetValueNames();
          string val;
          string dName;
          int indexVal;
          int countStartupProcessess;
          string[] allVal = new string[theValueNamesOfKeyHKCU.Length + theValueNamesOfKeyHKLM.Length];
          theValueNamesOfKeyHKLM.CopyTo(allVal, 0);
          theValueNamesOfKeyHKCU.CopyTo(allVal, theValueNamesOfKeyHKLM.Length);
          countStartupProcessess = allVal.Length;

                  string\[\] directories = Directory.GetDirectories("C:\\\\Documents and Settings");
                  foreach (string d in directories) 
                  {
                      foreach(string d1 in Directory.GetDirectories(d))
                      {
                          indexVal = d1.LastIndexOf("\\\\");
                          dName = d1.Substring(indexVal+1, d1.Length - (indexVal+1));
                          if (dName.ToUpper() == "START MENU")
                          {
                              foreach (string d2 in Directory.GetDirectories(d1))
                              {
                                  foreach (string d3 in Directory.GetDirectories(d2))
                                  {
                                      indexVal = d3.LastIndexOf("\\\\");
                                      dName = d3.Substring(indexVal + 1, d3.Length - (indexVal + 1));
                                      if (dName.ToUpper().Trim() == "STARTUP")
                                      {
                                          foreach (string f in Directory.GetFiles(d3))
                                          {
                                              indexVal = f.LastIndexOf(".");
                                              dName = f.Substring(indexVal + 1, f.Length - (indexVal + 1));
                                              if (dName.ToUpper() == "LNK" && dName.ToUpper() != "INI")
                                                  countStartupProcessess++;
                                          }
                                      }
          
          1 Reply Last reply
          0
          • N Neeraj Kr

            Actually I know about this registry key, but when I count the items in the Run Folder it comes out to be lesser than items listed in the startup section of the msconfig.

            -----Have A Nice Day-----

            M Offline
            M Offline
            Manas Bhardwaj
            wrote on last edited by
            #5

            Actually not. :) If you watch msconfig carefully, you can see that it might be having a extra number of start ups, but this registry key will give you only those which are enabled.

            N 1 Reply Last reply
            0
            • M Manas Bhardwaj

              Actually not. :) If you watch msconfig carefully, you can see that it might be having a extra number of start ups, but this registry key will give you only those which are enabled.

              N Offline
              N Offline
              Neeraj Kr
              wrote on last edited by
              #6

              Dude, the registry key you are talking about has nine entries on my computer where as the msconfig shows thirteen. And above all, they all the active. No one of them are INACIVE.. Check out my solution.

              -----Have A Nice Day-----

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups