How to count Startup Services and Processes using C#
-
How to count the number of startup services and processes using C#. Is there a specific Win32 Class for this.
-----Have A Nice Day-----
RegistryKey theKey = Registry.LocalMachine.OpenSubKey
@("Software\\Microsoft\\Windows\\CurrentVersion\\Run");
string[] theValueNamesOfKey = theKey.GetValueNames();:)
-
RegistryKey theKey = Registry.LocalMachine.OpenSubKey
@("Software\\Microsoft\\Windows\\CurrentVersion\\Run");
string[] theValueNamesOfKey = theKey.GetValueNames();:)
-
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-----
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++; } }
-
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-----
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.
-
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.