c# - Wrong value count -


i'm trying startups programs, have wrong value count.

i :

    private const int m_hkcu_path_code = 0;     private const int m_hklm_path_code = 1;     private const string m_registry_path = @"software\microsoft\windows\currentversion\run"; 

[...]

        m_initialstartupprograms = new dictionary<string, int>();          m_registrykey = registry.currentuser.opensubkey(m_registry_path);         foreach (string startupprograms in m_registrykey.getvaluenames())             m_initialstartupprograms.add(startupprograms, m_hkcu_path_code);          m_registrykey.close();          m_registrykey = registry.localmachine.opensubkey(m_registry_path);         foreach (string startupprograms in m_registrykey.getvaluenames())             m_initialstartupprograms.add(startupprograms, m_hklm_path_code);          m_registrykey.close(); 

but have 11 startup programs, whereas registry contains 14 startup programs. in fact, missing statup programs in localmachine. correctly startup programs in currentuser.

edit : don't understand...

http://puu.sh/9n1pd/86ffb17fed.png

on screen, cans see same folder there differnt keys ! (i accessed folders ccleaner.)

is program running 32 bit program on 64 bit machine? if looking @ software\wow6432node\microsoft\windows\currentversion\run

if using .net 4 or newer can tell folder check via openbasekey

here cleaned version of program uses it.

private void init() {     m_initialstartupprograms = new dictionary<string, int>();      loaddictionary(registryhive.localmachine, registryview.registry32, m_hklm_path_code);     loaddictionary(registryhive.localmachine, registryview.registry64, m_hklm_path_code);     loaddictionary(registryhive.currentuser, registryview.registry32, m_hkcu_path_code);     loaddictionary(registryhive.currentuser, registryview.registry64, m_hkcu_path_code); }  //instead of repeating same code on , over, make function  // call function repeatedly different parameters. private void loaddictionary(registryhive hive, registryview view, int pathcode) {     //based on name m_registrykey appears not local variables.     //because close them right away there no reason not make them local     // variables inside using statements.      using (var basekey = registrykey.openbasekey(hive, view))     using (var subkey = basekey.opensubkey(m_registry_path))     {         foreach (string startupprograms in subkey.getvaluenames())         {             m_initialstartupprograms.add(startupprograms, pathcode);         }     } } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -