Пример #1
0
HRESULT OCContextMenuRegHandler::UnregisterInprocServer(const CLSID& clsid)
{
	HRESULT hr = S_OK;

	wchar_t szCLSID[MAX_PATH];
	StringFromGUID2(clsid, szCLSID, ARRAYSIZE(szCLSID));

	wchar_t szSubkey[MAX_PATH];

	// Delete the HKCR\CLSID\{<CLSID>} key.
	hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey), L"CLSID\\%s", szCLSID);
	if (SUCCEEDED(hr))
	{
		hr = HRESULT_FROM_WIN32(RegDelnode(HKEY_CLASSES_ROOT, szSubkey));
	}

	return hr;
}
Пример #2
0
HRESULT OCContextMenuRegHandler::UnregisterShellExtContextMenuHandler(
	PCWSTR pszFileType, PCWSTR pszFriendlyName)
{
	if (pszFileType == NULL)
	{
		return E_INVALIDARG;
	}

	HRESULT hr;
	
	wchar_t szSubkey[MAX_PATH];

	// If pszFileType starts with '.', try to read the default value of the 
	// HKCR\<File Type> key which contains the ProgID to which the file type 
	// is linked.
	if (*pszFileType == L'.')
	{
		wchar_t szDefaultVal[260];
		hr = GetHKCRRegistryKeyAndValue(pszFileType, NULL, szDefaultVal,
			sizeof(szDefaultVal));

		// If the key exists and its default value is not empty, use the 
		// ProgID as the file type.
		if (SUCCEEDED(hr) && szDefaultVal[0] != L'\0')
		{
			pszFileType = szDefaultVal;
		}
	}

	// Remove the HKCR\<File Type>\shellex\ContextMenuHandlers\{friendlyName} key.
	hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey),
		L"%s\\shellex\\ContextMenuHandlers\\%s", pszFileType, pszFriendlyName);
	if (SUCCEEDED(hr))
	{
		hr = HRESULT_FROM_WIN32(RegDelnode(HKEY_CLASSES_ROOT, szSubkey));
	}

	return hr;
}
Пример #3
0
BOOL RegClean()
{
    HKEY hRegRoot;
    HKEY hSubKey;
    LONG rc;
    LONG query;
    DWORD dwIdIndex;
    CHAR idName[64];
    DWORD idSize = sizeof(idName);
    CHAR video[64];
    DWORD dwType = 0;
    CHAR lpDesc[256]; 
    DWORD dwSize= sizeof(lpDesc);
	BOOL res = FALSE;

    rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
						"SYSTEM\\CurrentControlSet\\Control\\Video",
						0,
						KEY_ALL_ACCESS,
						&hRegRoot);
    
    if (rc != ERROR_SUCCESS) {
        logError("RegClean Open Root Key Failed:%x, %d\n", GetLastError(), rc);
        return FALSE;
    }

    dwIdIndex = 0;
    do {
        query = RegEnumKeyEx(hRegRoot,
                            dwIdIndex,
                            &idName[0],
                            &idSize,
                            0,
                            NULL,
                            NULL,
                            NULL);
        idSize = sizeof(idName);
        dwIdIndex++;

        sprintf(video, "%s\\Video", idName);
        rc = RegOpenKeyEx(hRegRoot,
                            video,
                            0,
                            KEY_QUERY_VALUE,
                            &hSubKey);
        if (rc != ERROR_SUCCESS) {
            logError("RegClean Open Sub Key Failed: %x, %d\n", GetLastError(), rc);
			continue;
        }
        rc = RegQueryValueEx(hSubKey,
                "Service",
                0,
                &dwType,
                (PBYTE)&lpDesc,
                &dwSize);
        // Don't need to do this Check.
#if 0
        if (rc != ERROR_SUCCESS) {
            logPrint("Query Reg Sub Key Desc Failed:%x\n", GetLastError());
            goto QuerySubKeyFailed;
        }
#endif
        dwSize= sizeof(lpDesc);
        if (dwType == REG_SZ) {
            if (stricmp(lpDesc, DRIVER_NAME) == 0) {
        		RegCloseKey(hSubKey);
				hSubKey = NULL;
				// RegDeleteTree is not avalible on win2k winXp
				// rc = RegDeleteTree(hRegRoot, idName);
				res = RegDelnode(hRegRoot, idName);
				logInfo("RegClean %s %x %d\n", idName, GetLastError(), res);
			}
        }
		if (hSubKey) {
        	RegCloseKey(hSubKey);
		}
    } while (query != ERROR_NO_MORE_ITEMS);
    RegCloseKey(hRegRoot);

    return TRUE;
}