Question

Actually i have Path=Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run,andSoftware\\Microsoft\\Windows\\CurrentVersion\\Run and i am passing root key asHKEY_USESRSfrom which i am getting subkeys.then Iam Concatinating subkey+Path.....In loop i am gettingHKEY_USERS\S-1-5-19\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Run also actually which is not existing in registry...is there any function to check Complete path exists or not?

listData.RemoveAll();
        HKEY hrKey=HKEY_USERS,hKey; 
        if(hrKey==HKEY_USERS)
        {
            TCHAR    achKey[MAX_KEY_LENGTH];   // buffer for subkey name
            DWORD    cbName;                   // size of name string 
            TCHAR    achClass[MAX_PATH] = TEXT("");  // buffer for class name 
            DWORD    cchClassName = MAX_PATH;  // size of class string 
            DWORD    cSubKeys=0;               // number of subkeys 
            DWORD    cbMaxSubKey;              // longest subkey size 
            DWORD    cchMaxClass;              // longest class string 
            DWORD    cValues;              // number of values for key 
            DWORD    cchMaxValue;          // longest value name 
            DWORD    cbMaxValueData;       // longest value data 
            DWORD    cbSecurityDescriptor; // size of security descriptor 
            FILETIME ftLastWriteTime;      // last write time  
            DWORD i, retCode; 
            // Get the class name and the value count. 
        retCode = RegQueryInfoKey(hrKey,                    // key handle 
                             achClass,                // buffer for class name 
                            &cchClassName,           // size of class string 
                            NULL,                    // reserved 
                            &cSubKeys,               // number of subkeys 
                            &cbMaxSubKey,            // longest subkey size 
                            &cchMaxClass,            // longest class string 
                            &cValues,                // number of values for this key 
                            &cchMaxValue,            // longest value name 
                            &cbMaxValueData,         // longest value data 
                            &cbSecurityDescriptor,   // security descriptor 
                            &ftLastWriteTime);       // last write time 
            if (cSubKeys)
            {

                for (i=0; i<cSubKeys; i++) 
                { 
                    cbName = MAX_KEY_LENGTH;
                    retCode = RegEnumKeyEx(hrKey, i,achKey,&cbName,NULL,NULL,NULL,&ftLastWriteTime); 
                    if (retCode == ERROR_SUCCESS) 
                    {

                        CString subKey=achKey;
                        if(subKey!=_T(".DEFAULT")&&(subKey.Mid(subKey.ReverseFind('_')+1)!=_T("Classes")))
                        {                               
                            csRegistryPath=subKey+_T("\\")+csRegistryPath;
                            CLog::Log( csRegistryPath);
                        }
                    }
                }
            } 

csRegistryPath is array in calling function then once i will getS-1-5-19\Software\Microsoft\Windows\CurrentVersion\Run and S-1-5-19\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\RunOnce basing on this path i am performing further operations but actually HKEY_USERS\S-1-5-19\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\RunOnce not exist in registry if get this path i need to check if this is existing or not ? to do this isthere any API

Was it helpful?

Solution

For a Win32 API solution you use RegOpenKeyEx to test for existence of a key.

Do note that you must not hard code Wow6432Node. Use the KEY_WOW64_32KEY flag to specify that you want to look in the 32 bit view of the registry.

You would want to pass

STANDARD_RIGHTS_READ | KEY_WOW64_32KEY

to the samDesired argument of RegOpenKeyEx.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top