Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why RegConnectRegistry works in my exe but not via JNI?  RSS feed

 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've converted my exe to a DLL and am using it from JNI. I call RegConnectRegistry and pass it the server name (which was converted from jstring to wchar_t). When I print the server name out it is exactly right (or at least appears so), yet i get an error every time. Using this from the command line instead (via the .exe) it all works. Are there security restrictions in calling it from JNI? (I'm not running with a security manager)

Could I be converting something incorrectly?
 
Jean-Francois Briere
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What error do you get?
 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, now I'm officially confused. I had thought the problem was that my wchar_t string was wrong but that's not it. (see: my other post)

I changed my code so that I'm now just hardcoding in the chars* variables. When I call the method isLoggedOn( char* serverName, char* userName) from the command line against my .exe, everything works perfectly. When I call that exe from Java via getRuntime().exec(...) everything works perfectly. When I call it from JNI (by changing the exe to a DLL), it fails!

The error I get is:

"Unable to open HKEY_USERS for WebServer"

WebServer is the correct name and I'm not even passing it in -- it's hardcoded now! What's going on?
 
Jayesh Lalwani
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the Webserver a differrent machine on the network?

Are you running your Java app as a Windows service?
 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jayesh Lalwani:
Is the Webserver a differrent machine on the network?

Are you running your Java app as a Windows service?


No, it's actually the same computer. (And I know it's not a loopback problem because the exe version works) It's a laptop not connected to any network but with a card in it to allow loopbacks.
 
Jayesh Lalwani
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it's the same machine why don't you just use RegOpenKeyEx?

RegConnectRegistry is to connect to a regstry on another computer
 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jayesh Lalwani:
If it's the same machine why don't you just use RegOpenKeyEx?

RegConnectRegistry is to connect to a regstry on another computer


Because I'm writing the code to be able to work against remote and local machines. I just want to start programming locally first, then once that works take it on a network (since that can make bug-fixing difficult).
 
Jayesh Lalwani
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gotcha!! Since, Microsoft is "so helpful" with it's error message, we will have to resort to process of elimination to sort out the problem

The problem could be
a) your Java app is not able to connect to your registry service
b) somehow Windows thinks you don;t have the credentials to open the registry

So, you could try one or both of these things
a) try to use the IP address instead of server name.
b) try using RegOpenKeyEx . If RegOpenKeyEx fails too, it is probably some sort of authorization issue, or perhaps some bug in the code


I would try using RegOpenKeyEx first, because using that eliminates the network communications
 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jayesh Lalwani:
Gotcha!! Since, Microsoft is "so helpful" with it's error message, we will have to resort to process of elimination to sort out the problem

The problem could be
a) your Java app is not able to connect to your registry service
b) somehow Windows thinks you don;t have the credentials to open the registry

So, you could try one or both of these things
a) try to use the IP address instead of server name.
b) try using RegOpenKeyEx . If RegOpenKeyEx fails too, it is probably some sort of authorization issue, or perhaps some bug in the code


I would try using RegOpenKeyEx first, because using that eliminates the network communications


Well, the weird thing is that it works when the app is an exe but not when it's a DLL. It's not that the Java app is connecting to the registry or anything, but that the DLL for some reason keeps getting "bad network path" even though it's sending EXACTLY the same data/code as the exe. It makes no sense?! Any idea why the same exact method calls (with hard coded parameters) would act differently in an EXE vs a DLL? (And it shouldn't be a permission thing since it doesn't throw that error, it throws error 53, bad network path)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!