Andrei Ivanov

Hello all.

I would like to implement a little function that does the following:

Function is passed a URL in a string. Upon execution, it needs to open a new browser window and display that URL. The site at the URL is a JAVA applet.

I've tried the following:

Code Snippet

public void Start(string address)

{

Process.Start(address);

}

Now, while this works, it only opens 1 IE window or reuses the same window if one is already open, which doesn't work for me. Gotta be able to run it in a separate window.

So, trying

Code Snippet

public void Start(string address)

{

Process.Start("IExplore.exe", address);

}

Great, this open a new window per call to the function, except that this process can't find the JAVA path, so instead of running my applet at that address, I get the "This requires JRE version blah blah blah" message.

I've tried modifying the PATH env variable, but can't seem to get it to work.

Is there an implementation that can work for me

Thanks,

Andrei



Re: Visual C# General New Process and environment variables.

TaylorMichaelL

For the life of me I can't figure out how it would work in the first case and not the second. In the first case all it does is look up the association in registry and then run the program. It should be identical to the second case. Nevertheless there are a variety of things you can do to work around it. You should probably use ProcessStartInfo rather than passing the arguments directly to Start.

Option 1 is to set the working directory of the new process to wherever your path needs to be. This is an option in ProcessStartInfo.

Option 2 is to modify the environment variables that will be used to include the appropriate path. This is also an option in ProcessStartInfo.

Michael Taylor - 4/3/07

http://p3net.mvps.org





Re: Visual C# General New Process and environment variables.

Andrei Ivanov

I've tried modifying the PATH env var of the process by getting it, appending JAVA path, and setting it, and even that didn't work.

I'm completely stumped why this is happening.

I think next thing to try might be to get all the process info I can from a process that can find JAVA, and diff it against one that can't find it......

Until process has been started, I really can't get env vars, or working dir, can I

Thx,

Andrei





Re: Visual C# General New Process and environment variables.

TaylorMichaelL

Perhaps I misworded what I originally wrote. The environment variables of a process are inherited by its parent process. Ultimately everybody inherits from Explorer. When you start a new process you will get the environment variables defined by the parent. In general this will match what you defined in Control Panel/System/Advanced -> Environment Variables. You can modify this list before the process starts. The working directory of a process can also be set before it is started. You can do both of these using the ProcessStartInfo type. There are properties to set both of these.

I'm not convinced that it is necessarily a path problem for Java though. The Java runtime used by IE is not set through environment variables. I use the Sun Java RTE and I don't have a Java environment variable nor is it in my PATH variable. Inside IE you should see in the options dialog a setting that tells you what Java VM you're running. If it isn't right then IE won't work properly. It sounds more like it is a problem with IE not being able to find the Java files in the directory where you are loading the document from. Try setting the working directory to the place where your document you're loading is at.

Michael Taylor - 4/4/07

http://p3net.mvps.org





Re: Visual C# General New Process and environment variables.

Andrei Ivanov

The document is an IP address to a server that runs a java applet. So literally the arg is http://192.168.0.0/

I've run both processes side by side. The only difference I see so far in process properties that I can query are the verbs.

Working directory is "" for both, env vars are the same for both. Not sure what I would set the workingdir to in this case, I'm not accessing a file on my own server.





Re: Visual C# General New Process and environment variables.

TaylorMichaelL

You're using a non-standard IP address if it is 192.168.0.0. Normally addresses ending with .0 are reserved to avoid confusion with the subnet mask that is used to find the machine. Is this a standard machine on your network or did you recently add it I don't think it is causing your problem (I'm not a network expert) but I wouldn't be surprised if the router on your network got confused and sent the request to the wrong machine periodically.

In regards to your problem since it is a web server on the other end then things change quite a bit. It could be either a client or server problem. Who is generating the actual error - the browser or the server If the browser ultimately connects to a Java applet and runs it on the client side then it is a client issue. If the server tries to run some Java code and errors out then it is a server problem.

Here is something you can try. Open up IE and then connect to the address manually. Does it work How about if you open another tab in IE and do the same thing again Now open another instance of IE and try it again. Do they all work correctly At this point I'm scratching my head about how an internal component to IE (the Java RTE) can have problems when, from its point of view, there is no distinction between the two mechanisms to invoking IE. Have you tried enabling logging from the Java RTE I know Sun has this option but I'm not sure about your VM.

Another thing you can do is use Process Explorer (www.sysinternals.com - redirects to Microsoft) to view the command line and environment variables of IE after you start it from your app. You can run it both ways and see if there are any differences.

Michael Taylor - 4/4/07

http://p3net.mvps.org





Re: Visual C# General New Process and environment variables.

Andrei Ivanov

I used 192.168.0.0 as an example IP.

Here's what I found:

The IE window that was started with Process.Start(address) call has entries for Java and Microsoft VM under IE Tools->Internet Options->Advanced.

The IE window that was started with Process.Start("Iexplore.exe", address) does not have those entries.

One more difference found using process explorer (which I didn't see just printing out the env variables....dunno why): The PATH variable for both processes has the JRE path tacked onto the end of the PATH. The first process, however (one that works), also has JRE path in 8-char format (you know where dir/file paths get displayed as after 8 chars) added to the front of the PATH.

Now, this is all on Windows 2003 Server, not on XP, which makes things hard to verify (works on my XP dev machine).

I'm gonna have to explore this difference in explorer settings..

Thanks,

Andrei





Re: Visual C# General New Process and environment variables.

TaylorMichaelL

Sounds like maybe you have an extra copy of iexplore.exe lying around (maybe in the Java directory). It is possible that your Java RTE doesn't understand long filenames. I'd recommend that you take the 8.3 path and attach it to the END of the PATH variable and remove the one from the beginning. It annoys me when apps put their paths in front of the system paths. System paths should always be first otherwise you take a hit looking for things. Nevertheless you should probably use ProcExp to verify that the actual path to iexplorer.exe is the same in both cases. Sort of sounds like maybe they aren't although I don't know why. Good luck.

Michael Taylor - 4/4/07

http://p3net.mvps.org





Re: Visual C# General New Process and environment variables.

Andrei Ivanov

Figured it out.

Windows Server has 2 copies of IE: x86 and x64.

http:// extension is associated with x86 version of IE, iexplore.exe starts the x64 version.

Java applets are only supported on x86 so when JRE is installed it associates itself with x86 IE only. Installing x64 version of JRE doesn't do anything since Java x64 does not support applets. No Java support for x64 IE at this time at all.