Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advapi32Util can't read from registry as non-admin #101

Closed
myleshorton opened this issue Jul 19, 2012 · 5 comments
Closed

Advapi32Util can't read from registry as non-admin #101

myleshorton opened this issue Jul 19, 2012 · 5 comments

Comments

@myleshorton
Copy link

No problem reading as a user with admin privileges, but as non-admin I get:

com.sun.jna.platform.win32.Win32Exception: The system cannot find the file specified.
at com.sun.jna.platform.win32.Advapi32Util.registryGetStringValue(Advapi32Util.java:508)

Note this is reading from HKEY_CURRENT_USER, and I'm able to read through calling out to REG through Windows command prompt (from same Java process as gave the above error..).

@myleshorton
Copy link
Author

The above is from 3.4.1 (I think), just grabbed it from your dist directory a couple of days ago..

@dblock
Copy link
Member

dblock commented Jul 19, 2012

This could be a WOW64 redirect problem, maybe?

http://msdn.microsoft.com/en-us/library/windows/desktop/aa384182(v=vs.85).aspx

@TomGood75
Copy link

I know this is old, but I ran into the same problem and didn't find a clear answer. It is exactly as dblock mentioned, a WOW64 redirect problem. I was getting the same error as above, and upon doing a listing of HKEY_LOCAL_MACHINE\Software, realized windows was silently redirecting to the HKEY_LOCAL_MACHINE\Wow64Node\Software node based on the results returned. This was also causing my reads and writes to keys under the Software parent node to fail, because they didn't exist under the Wow64Node node.

After reading up on windows registry redirector {
redirector itself: http://msdn.microsoft.com/en-gb/library/aa384232%28VS.85%29.aspx
alternate views / workaround for it: http://msdn.microsoft.com/en-gb/library/aa384129%28VS.85%29.aspx
}
As a quick fix, I ended up just creating a local methods of registryKeyExists, registryGetStringValue, registrySetStringValue that were copies of the base methods, but with forcing the view to fix the redirect issue.

For example, in registryKeyExists, instead of:
int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ, phkKey);
change to:
int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ | 0x0100, phkKey);

You basically need to change the "REGSAM samDesired" parameter on the RegOpenKeyEx calls to have the view mask needed - I also ended up using the static variable WinNT.KEY_WOW64_64KEY instead of 0x0100 in the code to keep it cleaner instead of the above, but thought I'd leave the bitmask above in since it relates to the MSDN note a little clearer.

Good luck!

-- By the way, this issue was with a fresh pull today of jna and platform versions 3.5.2

@dblock
Copy link
Member

dblock commented Jun 3, 2013

This just says that we need to expose an additional parameter to the utility method so that the value of WinNT.KEY_READ isn't hard-coded. Maybe you can make a pull request?

@matthiasblaesing
Copy link
Member

Closing this as fix was merged a long time ago.

mstyura pushed a commit to mstyura/jna that referenced this issue Sep 9, 2024
…ading streams. (java-native-access#101)

Motivation:

We should support using AUTO_READ false and also be able to set read limits in general.

Modifications:

- Support manually reading
- Support limit the number of datagrams to read per read() operations.
- Support autoread setting for processing streams on the quic channel

Result:

Related to netty/netty-incubator-codec-quic#95
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants