#include "stdafx.h" #include <stdio.h> #include <windows.h> #define STATUS_SUCCESS 0
BOOL GetKeyPathFromKKEY(HKEY key,wchar_t *keys) { DWORD result = -1; if (key != NULL) { HMODULE dll = LoadLibraryW(L"ntdll.dll"); *keys = 0; if (dll != NULL) { typedef DWORD (__stdcall *NtQueryKeyType)( HANDLE KeyHandle, int KeyInformationClass, PVOID KeyInformation, ULONG Length, PULONG ResultLength);
NtQueryKeyType func = reinterpret_cast<NtQueryKeyType>(::GetProcAddress(dll, "NtQueryKey"));
if (func != NULL) { DWORD size = 0; result = func(key, 3, keys, 1024, &size); if (result == STATUS_SUCCESS) { keys[size / sizeof(wchar_t)] = L'\0'; lstrcpyW(keys, keys + 2); } } FreeLibrary(dll); } } return result; }
int main(int argc, char* argv[]) { HKEY key = NULL; LONG ret = ERROR_SUCCESS; wchar_t keys[1024]; ret = RegOpenKeyW(HKEY_CLASSES_ROOT, L".au\\OpenWithProgIds", &key); if (ret == ERROR_SUCCESS) { GetKeyPathFromKKEY(key,keys); wprintf(L"Key path for %p is '%ws'.", key, keys); RegCloseKey(key); } return 0; }
|
Comments