• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Windows system root

 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a way to get the %systemroot% property?
We can assume that the user has given us/java permission to access the file system etc.

I've tried :


and then getting the input and output streams and to push commands to, with no luck.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That should work. I will bet you are not putting a line separator on the end of the command. Remember, line separators are not platform independent, and the UNIX one ('\n') does not work on Windows (which expects "\n\r").
Don't hard code the line separator. Either use System.getProperties() to get it or use a PrintWriter or BufferedWriter which provide methods to place a line separator in the stream.
Don't forget to flush the stream after the line separator.
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well - using "cmd" the system-indepence is already lost.

But what is the %systemroot% property?
The filesystem-root?
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Charles Hasegawa:
Is there a way to get the %systemroot% property?
We can assume that the user has given us/java permission to access the file system etc.

I've tried :


and then getting the input and output streams and to push commands to, with no luck.



try {
Runtime rt = Runtime.getRuntime();
Process p = rt.exec("cmd /k echo %systemroot%");
InputStream is = p.getInputStream();
byte[] b = new byte[100];
is.read(b);
String s = new String(b);
System.out.println(s.trim());

} catch (Exception e) {
e.printStackTrace();
}

I just tried the above code and it worked for me.
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can get any environment variable value from any Windows OS flavor with this utily class:

And here is an example on how to use it (very simple indeed):
 
Charles Hasegawa
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks everyone, lots of good help.

Originally posted by Stefan Wagner:
well - using "cmd" the system-indepence is already lost.
But what is the %systemroot% property?
The filesystem-root?



We weren't trying for system independence with this - we know the client will be on a Win OS but it could be 98, 2k, XP, etc. This all came about because we have to download a dll to run a signature pad, and so we need to know the client's system32 directory location (which can be in the "windows" folder or "winnt" folder and can be on any drive, etc).

On WinOS, open a command prompt and tyep "ECHO %systemroot%" and you should get something like "c:\windows" (or whatever).
 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
May I humbly suggest that you don't do it through exec ("..cmd...")
but that you use JNI to call SHGetFolderPath()? If I understand
correctly you already use JNI for the DLL, therefore it's no sweat.
I also believe it is, well, slightly cleaner than calling cmd.

Best regards,
Petr
 
Stefan Wagner
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well - I don't have a windows to type in 'echo %systemroot%', but I got a hint:
If you're allowed to use java-1.5,

should work. But probably you're not allowed.
 
Don't play dumb with me! But you can try this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic