wood burning stoves 2.0*
The moose likes Java in General and the fly likes Registry Values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Registry Values" Watch "Registry Values" New topic
Author

Registry Values

S bitz
Ranch Hand

Joined: Jan 20, 2006
Posts: 80
Hi,
Is there a way in java to get the Logon User Name in the registry for windows authentication ?

Thanks
Bitz
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19066
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

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.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
S bitz
Ranch Hand

Joined: Jan 20, 2006
Posts: 80
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

Joined: Sep 12, 2004
Posts: 290

Native library means to develope an application in C which accesses the registry and then use JNI to use that app.


OCP/MCP/SCJP/SCWCD/IBM XML/SCMAD/SCEA-1
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

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

Joined: Dec 20, 2006
Posts: 2516
    
  10

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


OCUP UML fundamental and ITIL foundation
youtube channel
D Rog
Ranch Hand

Joined: Feb 07, 2004
Posts: 472


returns logon user name and it's portable


Retire your iPod and start with HD Android music player Kamerton | Minimal J2EE container is here | Light weight full J2EE stack | and build tool | Co-author of "Windows programming in Turbo Pascal"
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Registry Values