• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Registry Values

 
S bitz
Ranch Hand
Posts: 80
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Is there a way in java to get the Logon User Name in the registry for windows authentication ?

Thanks
Bitz
 
Henry Wong
author
Marshal
Pie
Posts: 20828
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The recommended way (if you can call it that) is to use JNDI. Unfortunately, you will also need to use a service provider that will connect to the windows registry. You will need to do a search on the Sun website to find a source.

If this "registry" is the active directory, then you could probably use the base JNDI libs, as active directory is compatible with LDAP.

Henry
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trying to use APIs to access the registry in windows makes your code non portable. If you are sure that your application will not be ported to other platforms, use a native library to read these values and use JNI to invoke this library.
 
S bitz
Ranch Hand
Posts: 80
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi John,
My application will not be ported to any other OS.
What is the native library you have mentioned? Could you please give me some more idea as to where can i get them or how i can create them?

Thanks
Bitz
 
Aryan Khan
Ranch Hand
Posts: 290
Java Oracle Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Native library means to develope an application in C which accesses the registry and then use JNI to use that app.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the native function that seems to be the one you want (I am not entirely sure).

Public Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" ( _
ByVal hKey As Long, _ ' Handle to open registry key
ByVal lpValueName As String, _ ' Name of value
ByVal lpReserved As Long, _ ' Reserved, must be 0
lpType As Long, _ ' Registry data type constant
lpData As Any, _ ' By reference variable for data
lpcbData As Long _ ' Number of bytes of data written
) As Long


You can use java's JNI to invoke functions that are native to that platform, using a language like C.
 
Jan Cumps
Bartender
Posts: 2576
11
C++ Linux Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A working example that uses the Windows reg command to read registry settings can be found on Real's.

It calls the reg query ... command to extract values from registry.
No JNI required.
It's not portable, but that seems to be no issue for you.

Don't know where the current user's name for nt authentication is stored.

Regards, Jan
 
D Rog
Ranch Hand
Posts: 472
Linux Objective C Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

returns logon user name and it's portable
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic