views:

21

answers:

2

For the life of me I can't figure out how to resolve the declared NTQueryKey value in my device driver. I looked for a device driver forum, but didn't find one.

Can someone point me to the right place? OSR isn't very responsive with dumb questions like how to link to NTQueryKey.

Here is my prototype:

NTSYSAPI NTSTATUS NTAPI NtQueryKey(HANDLE, KEY_INFORMATION_CLASS, PVOID, ULONG, ULONG *);

and it compiles fine, but the linker doesn't like it.

Thanks

A: 

In kernel mode you link to the Zw.... equivalent functions. See Here. NT.... functions are called from user mode (for example the Win32 subsystem would call the NT... functions).

Preet Sangha
I'm trying to use ZwQueryKey but I'm getting an STATUS_INVALID_HANDLE. All I'm trying to do is get the key name on a Windows 2003 machine in a PostCreateOpenKeyEx routine.
Iunknown
For completeness, a full discussion of the differences between the Nt and Zw variants is here: http://www.osronline.com/article.cfm?id=257.
snoone
+1  A: 

NtXXXX functions should not be called from kernel mode. Use the ZwXXXX functions instead. In your case, you want ZwQueryKey. It has the same signature as NtQueryKey, but it performs actions on the x86 required for talking with kernel mode, and it's provided by ntoskrnl.exe rather than by ntdll.dll.

Billy ONeal
The problem I have is I'm trying to open a user mode key. First I try ZwQueryKey and I get the error Invalid Handle, which I figured meant I need to use NTQueryKey.
Iunknown
@kunknown: What do you mean by user mode key? ZwQueryKey is the exact same function as NtQueryKey with respect to how it works. The only difference is that NtQueryKey does a bunch of syscall crap.
Billy ONeal
With a little help from OSR, I think I found the problem. I misunderstood the a "A pointer to the registry key object" is not a pointer to a handle. Trying ObOpenObjectByPointer now.
Iunknown