Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 13 of 13

Thread: Third party application utilizing Java portion of registry and environmental variable

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Third party application utilizing Java portion of registry and environmental variable

    Hello All,
    I have a interesting question and hopefully it is has simple solution. We are getting ready to deploy an application to the Enterprise here. This application requires Java and well the application also uses the HKLM\Software\JavaSoft\Prefs key to store its configuration/preferences. Now I know Java reads things differently than windows so to speak. For Example:

    In the Windows registry if I was going to store a Server name under the Javasoft\Prefs key it would be as follows

    Type=RegSz
    ValueName=ServerName
    Data= /S/E/R/V/E/R-1

    One of the values we are trying to store requires a value that is a filepath. The filepath we would like to use is basically a subfolder under the User's my documents folder so lets call it User1\My Documents\Application1

    So again my understanding is that it would be
    Type=RegSz
    ValueName=App1FilePath
    Data=//C://Users/User1/My /Documents/Application1

    I am able to set this value in a msi/mst. However and here is where my question is I really do not want to hardcode to drive letter. I would prefer to use a Java Environmental Variable that basically would set to the current user without hardcoding drive letter or user with the rest being:

    ??This would be EnvVar?? /My /Documents/Application1/Temp

    Is there a way to do this or am I stuck hardcoding to drive letter and user.


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Third party application utilizing Java portion of registry and environmental vari

    System.getProperty("user.dir"));

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Third party application utilizing Java portion of registry and environmental vari

    I would prefer to use a Java Environmental Variable
    Also Look at the System class. It has a method for getting the value of an Environment variable.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Junior Member
    Join Date
    Aug 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Third party application utilizing Java portion of registry and environmental vari

    I would rather use an environmental variable also....

    Let me try to make this a little clearer...


    So currently in the registry I have a regsz entry that goes like this:

    temp value=/C:///Users//user01///My /Documents///Applicationname///temp

    Okay now instead of what's above I would like to use something like:

    Javaenvironmentalvariable(Users)+//Javaenvironmentalvariable(currentuser)///My /Documents///Applicationname///temp

    now if one variable will cover the current user in windows thats fine two

    unless i am misunderstanding the first poster and he is telling me to use something like

    ///user.dir//My /Documents///Applicationname///temp

  5. #5
    Junior Member
    Join Date
    Aug 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Third party application utilizing Java portion of registry and environmental vari

    The reason for all this just to explain is one I never like to hardcode a drive letter. Two the the drive we are using is going to be a network drive which is fine for users but admins do not have that same luxury. So while hardcoding would work for users. Admins would get an error and if for some reason down the line they change what drive letter your using for that network drive then everybody gets an error.
    Last edited by rjnagy; August 27th, 2012 at 05:11 PM. Reason: clarification and typo

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Third party application utilizing Java portion of registry and environmental vari

    Can you write a test program to show what you are trying to do?
    I don't see any problem building a String by concatenating the values of Environment variables with other Strings.

    How are you going to use the String that you build?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Aug 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Third party application utilizing Java portion of registry and environmental vari

    Norm all this is, is a string value for a registry storing a filepath location. The default by the program sets it to /C:///Users//user01///My /Documents///Applicationname///Temp
    I just want to get away from hardcoding it. I can hardcode it in the registry to the network drive letter they are currently using. I just hate to do that. I was hoping there was a standard java environmental variable for basically C:\Users\CurrentUserName\ so basically the registry entry would be Variable///My /Documents///Applicationname///Temp

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Third party application utilizing Java portion of registry and environmental vari

    a standard java environmental variable
    AFAIK Java doesn't set any Environment variables. It's up to the users.
    Try this to see what's available from java:
     
    		Properties props = System.getProperties();
    		props.list(System.out);
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Aug 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Third party application utilizing Java portion of registry and environmental vari

    No it doesn't your correct. Howevery my understanding is that java doesn't read the registry the same as windows does

    so for example in windows
    I can use %USERNAME% well Java doesnt understand that

    If I set a filepath in the windows registry it will usually use the following pattern

    app1tempfolder regsz c:\Users\user01\My Documents\App1\Temp

    Well Java doesn't understand that so it would be transformed to

    app1tempfolder regsz /C:///Users//user01///My /Documents/App1/Temp

    thats fine but what I am looking to do is basically wildcard the /C:///Users//user01 that would apply to whoever the current user is and that Java can read and understand.

  10. #10
    Junior Member
    Join Date
    Aug 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Third party application utilizing Java portion of registry and environmental vari

    While the app itself is not Java it relies on Java's JavaSoft/Prefs key to hold and store configuration information

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Third party application utilizing Java portion of registry and environmental vari

    Did you try the code I posted?
    If you don't understand my answer, don't ignore it, ask a question.

  12. #12
    Junior Member
    Join Date
    Aug 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Third party application utilizing Java portion of registry and environmental vari

    No I am going to test here in a couple

  13. #13
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Third party application utilizing Java portion of registry and environmental vari

    Perhaps your request is blocked by security.
    This link may help

Similar Threads

  1. Does Java create the following undeletable embedded-null registry entry..?
    By thedarkness in forum Java Theory & Questions
    Replies: 2
    Last Post: November 7th, 2011, 03:48 PM
  2. Java Installation with no Registry Key?
    By ch103 in forum Java Theory & Questions
    Replies: 1
    Last Post: October 20th, 2011, 06:41 PM
  3. Evaluate the environmental flexibility of programming in Java?
    By azzic7 in forum Java Theory & Questions
    Replies: 1
    Last Post: June 26th, 2010, 11:57 AM
  4. control third party page in java.
    By kirti in forum Member Introductions
    Replies: 1
    Last Post: May 2nd, 2010, 03:33 PM