[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

HELP! getRunTime failing ONLY for "Program Files" directory!

Posted on 2005-04-06
24
Medium Priority
?
287 Views
Last Modified: 2010-03-31
Dear Experts,

I have a nasty security-related problem.

I just installed some anti-spyware software on my PC (Windows 2000 Pro), which failed badly.  I've since uninstalled it, rebooted, etc.  However, I still have this very specific problem:

Existing Java code (a stand-alone application, not an applet) that used to work using getRunTime no longer works FOR THE "PROGRAM FILES" DIRECTORY ONLY!

Specifically, I used to be able to do this:

    String s = "C:\\Program Files\\Microsoft Office\\Office10\\EXCEL.EXE";
    Runtime r = Runtime.getRuntime();
    try
    {
      Process p = r.exec(s);
    }
    catch (IOException ex)   { }

Now, it fails with Java.io.IOException 193, which translates to "not a valid WIN32 application".

I'm pretty sure the anti-spyware set some sort of security switch somewhere that's specific to Java (or possibly cmd.exe) and the Program Files directory.  Do you folks have any ideas on where I should look?

These are the things my testing has revealed so far:

If I rewrite the process statement to:

  Process p = Runtime.getRuntime().exec(new String[] {"cmd.exe", "/c", s});

it DOES work.  (That's not a valid solution for me, but it's certainly a BIG clue.)

I have opened up all the normal security as much as I can, and that doesn't help.  For instance, I give "Full Control" to "Everyone" for the entire "Program Files" directory, etc.

It's not the space in "Program Files".

There is nothing wrong with EXCEL.EXE itself.  I can run it directly by double-clicking on it.

The same JRE as always is being used to CALL getRunTime, and that JRE was not (directly, anyway) modified by the anti-spyware.  The JRE is NOT Microsoft's--it was downloaded direct from Sun.  However, I'm NOT certain that it's the same JRE that getRunTime ITSELF is using.  I'm vague on all that.

It's not just my code that was affected.  At least one other vendor's application had been hurt by this.  I don't know it that was Java-related.

Any help would be greatly appreciated!

Thanks,
BrianMc1958


0
Comment
Question by:BrianMc1958
  • 8
  • 6
  • 6
  • +3
24 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 13717583
What about
>> Process p = r.exec("\"" + s + "\"");
0
 
LVL 37

Assisted Solution

by:zzynx
zzynx earned 400 total points
ID: 13717597
I think the reason is the space in "Program Files"
0
 
LVL 37

Expert Comment

by:zzynx
ID: 13717624
>> Process p = r.exec(s);
This tries to execute the program

C:\Program                                          //  which is indeed not a valid WIN32 application

with the parameter

Files\Microsoft Office\Office10\EXCEL.EXE
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Assisted Solution

by:TimYates
TimYates earned 400 total points
ID: 13717639
Use:

    String s = "\"C:\\Program Files\\Microsoft Office\\Office10\\EXCEL.EXE\"";
   
0
 
LVL 37

Expert Comment

by:zzynx
ID: 13717644
Writing it like
>> Process p = Runtime.getRuntime().exec(new String[] {"cmd.exe", "/c", s});
internally puts quotes around it.
You run the cmd.exe with as parameters /c and the content of s
0
 
LVL 37

Expert Comment

by:zzynx
ID: 13717658
That's indeed what I said, Tim ;°)
0
 
LVL 35

Expert Comment

by:TimYates
ID: 13717826
>>  That's indeed what I said, Tim ;°)

Oh yeah...  took a bit of working out, that did ;-)  hehehe soz...
0
 

Author Comment

by:BrianMc1958
ID: 13717882
Dear Experts,

Thanks, but I have verified that it's not the space.  I created this directory:

C:\HAS SPACE

(pretty clever naming convention, eh?)

and copied Excel to it, and the code DID work.  So I know it's not the space.  The problem is specific to the Program Files directory itself.  

Anyway, changing my code is not a valid solution for me, as other applications have been affected, and I can't fix them by changing their code.  I need to undo whatever it was that the anti-spyware software did.

Any more ideas?  

Thanks,
--BrianMc1948
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 400 total points
ID: 13717980
>>It's not the space in "Program Files".

Are you sure? What happens with

String s = "C:/PROGRA~1/MICROS~1/Office10/EXCEL.EXE";

?
0
 
LVL 14

Assisted Solution

by:StillUnAware
StillUnAware earned 400 total points
ID: 13718287
I think You should try to install that anti-spyware sowtware again, or find the newer version. Then uninstall it without errors. This MAY help, but may not too.
0
 

Author Comment

by:BrianMc1958
ID: 13718360
To CEHJ:  No luck.  But NICE TRY!  I should have tried that.  You'll get at least the consolation prize here!

To StillUnAware:  That software will get re-loaded on my machine when they pry my cold dead hand from the mouse.  (It uninstalled OK.  It merely failed to run at all correctly.)

I should probably say, as an added clue, when it did run, the first thing it did was tell me that I had a directory called "Program...", and this could cause problems, and did I want to rename it!!! (I said NO).

Any more ideas?  I'm a little DESPERATE here!

Thanks,
BrianMc1958
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13718680
What happens when you try my last at the command line?

I'm also a little puzzled by

>>That's not a valid solution for me

;-)
0
 

Author Comment

by:BrianMc1958
ID: 13719208
To CEHJ: I get the same error message when I try your last command.  Rewriting my code is not a good solution because other applications on my machine have also been adversely affected, and I can't re-write their code.  So I really want to undo what the anti-spyware did.

Thanks again,
--BrianMc1958
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13719311
>> I get the same error message when I try your last command.

OK, and what is the output of

dir C:/PROGRA~1/MICROS~1/Office10/EXCEL.EXE

?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13719318
Sorry - slashes the wrong way around for that ;-)
0
 

Author Comment

by:BrianMc1958
ID: 13720166
CEHJ--

OK.  That DOES work.  I plugged it into my program (and changed MICROS~1 to MICROS~2).  So it DOES seem to have something to do with spaces.

Yet I just re-tested my previous "spaces" example like this:

    String s = "C:\\HASABCD SPACE\\excel.exe";

I changed the test to "HASABCD" to match the number of letters in "Program" (Hey, I said I was getting desperate).  The above string still works AS IS.

So one interpretation of all this is that you can't have spaces--but only for the Program Files directory!  Is there any rationality in the universe?

Failing that, any more ideas on what might be CAUSING this behavior?

Foaming at the Mouth,
BrianMc1958
0
 

Author Comment

by:BrianMc1958
ID: 13720259
p.s.: I mentioned this before, but maybe I should repeat here:

If I rewrite the process statement to:

  Process p = Runtime.getRuntime().exec(new String[] {"cmd.exe", "/c", s});

it DOES work.  (That's not a valid solution for me, but it's certainly a BIG clue.)


(I don't really understand the significance of including the "cmd.exe".  I would have assumed it would default to that anyway...)

--BrianMc1958
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13720539
If you put the directory containing excel.exe on your PATH, you should be able to

Process p = Runtime.getRuntime().exec("excel.exe");
0
 
LVL 92

Assisted Solution

by:objects
objects earned 400 total points
ID: 13721536
Does this problem happen on all machines, or just the one.
If just the one then it may be related to you box and not the code.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 13724364
>> I don't really understand the significance of including the "cmd.exe".  
See my previous explanation

>> So one interpretation of all this is that you can't have spaces--but only for the Program Files directory!
That would be strange, isn't it?

>> the first thing it did was tell me that I had a directory called "Program...", and this could cause problems,
>> and did I want to rename it!!! (I said NO).
You did right.
What's the quality of a program that would need one of your directories to be renamed to be able to work correctly?
btw, what was the name of that anti-spyware software?
0
 

Author Comment

by:BrianMc1958
ID: 13726930
To Everybody:  Well, I'm afraid I don't have any sort of full explanation for this one.  I do have a couple of work-arounds to solve the immediate problems, and it looks like I'll have to go with those now.

Thank you all for your help.

To zzynx:  The software was actually Microsoft's Anti-Spyware (Beta).  To be fair, it caused no problems on half a dozen other machines here.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 13727009
Just to check that the space you see in your "Program Files" directory really IS a space:
can you go to it in a DOS session by typing:
C:\>cd "Program Files"

It sounds ridiculous, but I know of malpractices to replace the space by another ASCII character the does look like a space
Just to be sure
0
 
LVL 37

Expert Comment

by:zzynx
ID: 13727060
Thanks
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13736042
:-)
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses
Course of the Month20 days, 4 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question