| 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: 16687
|
|
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: 6588
|
|
|
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 - SCJP Mocks - SCJP 5 Mock exam (Word document ) - SCJP 5 Mock exam in Java.Inquisition format
|
 |
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: 289
|
|
|
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: 6588
|
|
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: 2343
|
|
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
ITIL foundation
|
 |
D Rog
Ranch Hand
Joined: Feb 07, 2004
Posts: 471
|
|
returns logon user name and it's portable
|
Get power of your iPod with MediaChest | Minimal J2EE container is here | Light weight full J2EE stack | My blog | Co-author of "Windows programming in Turbo Pascal"
|
 |
 |
|
|
subject: Registry Values
|
|
|