Search code examples
c#windowsregistry

c# check if program runs on startup


I would like to check if a certain program runs on the computer's startup,i accessed the win32 RegistryKey class for that:

 private void Form1_Load(object sender, EventArgs e)
    {
        bool ok = isOnRegistryStartup("iFilter");
        MessageBox.Show(ok.ToString());
    }
    private bool  isOnRegistryStartup(string key)
    {
       RegistryKey RegistryKey = Registry.CurrentUser.OpenSubKey
                ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
        if (registryKey.GetValue(key)!=null)
        {
            return true;

        }
        return false;

    }

The output was True indeed,because the program actually runs on the windows startup,but when i disabled that program startup by the Task manager(and it's status became disabled),the next time i runned the code above the result was still True,eventhough that program is not part of the startup programs anymore.

That leads me to a simple conclusion that when the windows task manager disables a startup program,it doesn't delete it's key in the registry key,but it changes another value of it..but i wasn't able to find out what's that changed value.

I hope someone can help.

Thanks.


Solution

  • Because setting it disabled on Task Manager doesn't remove its entry in:

    HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
    

    But rather setting corresponding value (From 0200 0000000... to 0300 0000 xxxxx....) in:

    HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run