Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > accessing the registry

Reply
Thread Tools

accessing the registry

 
 
soni29
Guest
Posts: n/a
 
      07-16-2003
hi,
i know that since the registry is only part of windows there probably
isn't a class in the sdk that will allow me to read from it. but does
anyone know of any free third party classes i can use? i've searched
and read about using jni, but don't know much about c or how to get
into the registry using c++. also on some forums someone mentioned
using the preferences class in the sdk, but i'm not 100% about that.
what i need to do is find out if the user has ms office installed on
their pc, if so where, i need to be able to launch office exe from my
app, we were building something we thought was going to run on linux
and windows, but all of a sudden my manager came and said forget it
now only windows, and he wants to try to add the launching ms office
suite into it. any ideas?

Thank you.
 
Reply With Quote
 
 
 
 
Tim Tyler
Guest
Posts: n/a
 
      07-16-2003
soni29 <(E-Mail Removed)> wrote:

: i know that since the registry is only part of windows there probably
: isn't a class in the sdk that will allow me to read from it. but does
: anyone know of any free third party classes i can use?
: i've searched and read about using jni, but don't know much about c or
: how to get into the registry using c++. also on some forums someone
: mentioned using the preferences class in the sdk, but i'm not 100%
: about that.

You can read from the registry in Java using java.util.prefs.

However you can only read out things you've put in.

The location of the MS office suite won't fit in that category.

Have you tried "exec"ing an appropriate file type?
--
__________
|im |yler http://timtyler.org/ http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      07-16-2003
On Wed, 16 Jul 2003 19:18:19 +0100, "Andy Flowers"
<(E-Mail Removed)> wrote or quoted :

>> : i know that since the registry is only part of windows there probably
>> : isn't a class in the sdk that will allow me to read from it. but does
>> : anyone know of any free third party classes i can use?
>> : i've searched and read about using jni, but don't know much about c or
>> : how to get into the registry using c++. also on some forums someone
>> : mentioned using the preferences class in the sdk, but i'm not 100%
>> : about that.


you need a tiny bit of C++ and JNI glue to hook into the registry
manipulating api.

I would create it for you for $10 US.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
Grant Wagner
Guest
Posts: n/a
 
      07-16-2003
soni29 wrote:

> hi,
> i know that since the registry is only part of windows there probably
> isn't a class in the sdk that will allow me to read from it. but does
> anyone know of any free third party classes i can use? i've searched
> and read about using jni, but don't know much about c or how to get
> into the registry using c++. also on some forums someone mentioned
> using the preferences class in the sdk, but i'm not 100% about that.
> what i need to do is find out if the user has ms office installed on
> their pc, if so where, i need to be able to launch office exe from my
> app, we were building something we thought was going to run on linux
> and windows, but all of a sudden my manager came and said forget it
> now only windows, and he wants to try to add the launching ms office
> suite into it. any ideas?
>
> Thank you.


Why do you need to read the Registry in order to launch MS Office
applications?

Runtime rt = Runtime.getRuntime();
Process p = rt.exec("cmd /c start MyWordDocument.doc");

If you want the path to a Microsoft Office program that handles a
particular document type, then you can retrieve that as well:

import java.io.*;

public class FileHandler {
public static void main(String[] s) {
String extension = "";
if (s.length == 1) {
extension = s[0];
try {
String output;
Runtime rt = Runtime.getRuntime();
Process p = rt.exec("cmd.exe /c " +
"for /f \"tokens=2 delims==\" %a " +
"in ('assoc ." + extension + "') " +
"do @for /f \"tokens=2 delims==\" %b " +
"in ('ftype %a') do @echo %b");

InputStreamReader isr = new
InputStreamReader(p.getInputStream());
BufferedReader br = new BufferedReader(isr);
try {
while ((output = br.readLine()) != null) {
System.out.println(output);
}
} catch (IOException e) {
System.err.println(e);
}
} catch (IOException e1) {
System.err.println(e1);
}
} else {
System.out.println("Usage: FileHandler [extension]");
}
}
}

"java FileHandler doc" reports "C:\Program Files\Microsoft
Office\Office\Winword.exe" /n on my machine.

Note that the above will only work on Windows 2000/XP.

--
| Grant Wagner <(E-Mail Removed)>

 
Reply With Quote
 
Eugene Toporov
Guest
Posts: n/a
 
      07-17-2003
(E-Mail Removed) (soni29) wrote in message news:<(E-Mail Removed). com>...
> hi,
> i know that since the registry is only part of windows there probably
> isn't a class in the sdk that will allow me to read from it. but does
> anyone know of any free third party classes i can use?


There is a fully-functional registry support available in WinPack for
JNIWrapper (http://www.jniwrapper.com/winpack_fe....jsp#registry).
Check the WinPack Demo to see the abilities.

Hope this helps.
Good Luck!
EToporov
 
Reply With Quote
 
soni29
Guest
Posts: n/a
 
      07-17-2003
Got it, thank you.

Grant Wagner <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> soni29 wrote:
>
> > hi,
> > i know that since the registry is only part of windows there probably
> > isn't a class in the sdk that will allow me to read from it. but does
> > anyone know of any free third party classes i can use? i've searched
> > and read about using jni, but don't know much about c or how to get
> > into the registry using c++. also on some forums someone mentioned
> > using the preferences class in the sdk, but i'm not 100% about that.
> > what i need to do is find out if the user has ms office installed on
> > their pc, if so where, i need to be able to launch office exe from my
> > app, we were building something we thought was going to run on linux
> > and windows, but all of a sudden my manager came and said forget it
> > now only windows, and he wants to try to add the launching ms office
> > suite into it. any ideas?
> >
> > Thank you.

>
> Why do you need to read the Registry in order to launch MS Office
> applications?
>
> Runtime rt = Runtime.getRuntime();
> Process p = rt.exec("cmd /c start MyWordDocument.doc");
>
> If you want the path to a Microsoft Office program that handles a
> particular document type, then you can retrieve that as well:
>
> import java.io.*;
>
> public class FileHandler {
> public static void main(String[] s) {
> String extension = "";
> if (s.length == 1) {
> extension = s[0];
> try {
> String output;
> Runtime rt = Runtime.getRuntime();
> Process p = rt.exec("cmd.exe /c " +
> "for /f \"tokens=2 delims==\" %a " +
> "in ('assoc ." + extension + "') " +
> "do @for /f \"tokens=2 delims==\" %b " +
> "in ('ftype %a') do @echo %b");
>
> InputStreamReader isr = new
> InputStreamReader(p.getInputStream());
> BufferedReader br = new BufferedReader(isr);
> try {
> while ((output = br.readLine()) != null) {
> System.out.println(output);
> }
> } catch (IOException e) {
> System.err.println(e);
> }
> } catch (IOException e1) {
> System.err.println(e1);
> }
> } else {
> System.out.println("Usage: FileHandler [extension]");
> }
> }
> }
>
> "java FileHandler doc" reports "C:\Program Files\Microsoft
> Office\Office\Winword.exe" /n on my machine.
>
> Note that the above will only work on Windows 2000/XP.

 
Reply With Quote
 
soni29
Guest
Posts: n/a
 
      07-17-2003
Thank you again for the response and solution, if possible could you
tell me what this means in your code:

Process p = rt.exec("cmd.exe /c " +
"for /f \"tokens=2 delims==\" %a " +
"in ('assoc ." + extension + "') " +
"do @for /f \"tokens=2 delims==\" %b " +
"in ('ftype %a') do @echo %b");

i know the Process class, and cmd.exe just trying to see the for
/f.... where did that come from?

Thank you.

(E-Mail Removed) (soni29) wrote in message news:<(E-Mail Removed). com>...
> Got it, thank you.
>
> Grant Wagner <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> > soni29 wrote:
> >
> > > hi,
> > > i know that since the registry is only part of windows there probably
> > > isn't a class in the sdk that will allow me to read from it. but does
> > > anyone know of any free third party classes i can use? i've searched
> > > and read about using jni, but don't know much about c or how to get
> > > into the registry using c++. also on some forums someone mentioned
> > > using the preferences class in the sdk, but i'm not 100% about that.
> > > what i need to do is find out if the user has ms office installed on
> > > their pc, if so where, i need to be able to launch office exe from my
> > > app, we were building something we thought was going to run on linux
> > > and windows, but all of a sudden my manager came and said forget it
> > > now only windows, and he wants to try to add the launching ms office
> > > suite into it. any ideas?
> > >
> > > Thank you.

> >
> > Why do you need to read the Registry in order to launch MS Office
> > applications?
> >
> > Runtime rt = Runtime.getRuntime();
> > Process p = rt.exec("cmd /c start MyWordDocument.doc");
> >
> > If you want the path to a Microsoft Office program that handles a
> > particular document type, then you can retrieve that as well:
> >
> > import java.io.*;
> >
> > public class FileHandler {
> > public static void main(String[] s) {
> > String extension = "";
> > if (s.length == 1) {
> > extension = s[0];
> > try {
> > String output;
> > Runtime rt = Runtime.getRuntime();
> > Process p = rt.exec("cmd.exe /c " +
> > "for /f \"tokens=2 delims==\" %a " +
> > "in ('assoc ." + extension + "') " +
> > "do @for /f \"tokens=2 delims==\" %b " +
> > "in ('ftype %a') do @echo %b");
> >
> > InputStreamReader isr = new
> > InputStreamReader(p.getInputStream());
> > BufferedReader br = new BufferedReader(isr);
> > try {
> > while ((output = br.readLine()) != null) {
> > System.out.println(output);
> > }
> > } catch (IOException e) {
> > System.err.println(e);
> > }
> > } catch (IOException e1) {
> > System.err.println(e1);
> > }
> > } else {
> > System.out.println("Usage: FileHandler [extension]");
> > }
> > }
> > }
> >
> > "java FileHandler doc" reports "C:\Program Files\Microsoft
> > Office\Office\Winword.exe" /n on my machine.
> >
> > Note that the above will only work on Windows 2000/XP.

 
Reply With Quote
 
Daniel Hagen
Guest
Posts: n/a
 
      07-18-2003
(E-Mail Removed) (soni29) wrote in message news:<(E-Mail Removed). com>...
> hi,
> i know that since the registry is only part of windows there probably
> isn't a class in the sdk that will allow me to read from it. but does
> anyone know of any free third party classes i can use? i've searched


Depends on the VM you are using. With the Microsoft VM, you can use
the Registry Classes from com.ms.wfc.app for reading from and writing
to the registry.

Regards

Daniel Hagen
 
Reply With Quote
 
Grant Wagner
Guest
Posts: n/a
 
      07-18-2003
cmd.exe /c just executes the command that follows it in a Windows NT command prompt, the rest is:

for /f "tokens=2 delims==" %a in ('assoc .doc') do @for /f "tokens=2 delims==" %b in ('ftype %a') do @echo %b

- for /f executes the "for" command with the ability to retrieve formatting
- "tokens=2 delims==" says, split the retrieved result at "=" and return the 2nd token
- %a is the variable to place the result in
- 'assoc .doc' is executed and in the case of .doc, returns ".doc=Word.Document.8"
- "Word.Document.8" (token 2) is placed in %a
- the "do" is preformed
- @for /f executes "for" with formatting options again, the @ says to suppress echoing the command
- 'ftype %a' (%a now contains Word.Document. is executed, and the stuff after the = is placed in %b
- %b is then @echoed (again, @ suppresses the actual command), so Java can retrieve the result

All the above basically executes:

assoc .doc
returns ".doc=Word.Document.8"
ftype Word.Document.8
returns "Word.Document.8="C:\Program Files\Microsoft Office\Office\Winword.exe" /n"

I came up with this solution when I needed access to the "help application" for a particular file type in some
batch files, the nice thing is that if you have a language that can call system commands (such as Java), it
works equally well there, all without requiring any actual Registry access.

I also wanted to demonstrate the power of the "for" command in Windows NT.

soni29 wrote:

> Thank you again for the response and solution, if possible could you
> tell me what this means in your code:
>
> Process p = rt.exec("cmd.exe /c " +
> "for /f \"tokens=2 delims==\" %a " +
> "in ('assoc ." + extension + "') " +
> "do @for /f \"tokens=2 delims==\" %b " +
> "in ('ftype %a') do @echo %b");
>
> i know the Process class, and cmd.exe just trying to see the for
> /f.... where did that come from?
>
> Thank you.
>
> (E-Mail Removed) (soni29) wrote in message news:<(E-Mail Removed). com>...
> > Got it, thank you.
> >
> > Grant Wagner <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> > > soni29 wrote:
> > >
> > > > hi,
> > > > i know that since the registry is only part of windows there probably
> > > > isn't a class in the sdk that will allow me to read from it. but does
> > > > anyone know of any free third party classes i can use? i've searched
> > > > and read about using jni, but don't know much about c or how to get
> > > > into the registry using c++. also on some forums someone mentioned
> > > > using the preferences class in the sdk, but i'm not 100% about that.
> > > > what i need to do is find out if the user has ms office installed on
> > > > their pc, if so where, i need to be able to launch office exe from my
> > > > app, we were building something we thought was going to run on linux
> > > > and windows, but all of a sudden my manager came and said forget it
> > > > now only windows, and he wants to try to add the launching ms office
> > > > suite into it. any ideas?
> > > >
> > > > Thank you.
> > >
> > > Why do you need to read the Registry in order to launch MS Office
> > > applications?
> > >
> > > Runtime rt = Runtime.getRuntime();
> > > Process p = rt.exec("cmd /c start MyWordDocument.doc");
> > >
> > > If you want the path to a Microsoft Office program that handles a
> > > particular document type, then you can retrieve that as well:
> > >
> > > import java.io.*;
> > >
> > > public class FileHandler {
> > > public static void main(String[] s) {
> > > String extension = "";
> > > if (s.length == 1) {
> > > extension = s[0];
> > > try {
> > > String output;
> > > Runtime rt = Runtime.getRuntime();
> > > Process p = rt.exec("cmd.exe /c " +
> > > "for /f \"tokens=2 delims==\" %a " +
> > > "in ('assoc ." + extension + "') " +
> > > "do @for /f \"tokens=2 delims==\" %b " +
> > > "in ('ftype %a') do @echo %b");
> > >
> > > InputStreamReader isr = new
> > > InputStreamReader(p.getInputStream());
> > > BufferedReader br = new BufferedReader(isr);
> > > try {
> > > while ((output = br.readLine()) != null) {
> > > System.out.println(output);
> > > }
> > > } catch (IOException e) {
> > > System.err.println(e);
> > > }
> > > } catch (IOException e1) {
> > > System.err.println(e1);
> > > }
> > > } else {
> > > System.out.println("Usage: FileHandler [extension]");
> > > }
> > > }
> > > }
> > >
> > > "java FileHandler doc" reports "C:\Program Files\Microsoft
> > > Office\Office\Winword.exe" /n on my machine.
> > >
> > > Note that the above will only work on Windows 2000/XP.


--
| Grant Wagner <(E-Mail Removed)>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help:win95 registry vs. winxp registry wege Computer Support 3 06-09-2006 06:28 PM
How to read a registry key from Windows registry ? Leny Java 3 02-01-2005 07:54 AM
Interpretation of registry log of tweakui produced registry alteration vincemoon@rcn.com ASP .Net 0 01-10-2005 02:53 AM
Reading registry key throws "Requested registry access is not allowed." HK ASP .Net 1 04-01-2004 04:44 PM



Advertisments