C#.Net Checking for Java

Questions about programming languages and debugging
Post Reply
User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

C#.Net Checking for Java

Post by ayu »

So I needed to write something in C#.Net that cecks if Java is installed.
Currently what I do is that I check if the java.exe file exists (which it does, and the program can find it without any issues).

But when I try to run it and get the info, it fails.
The code I'm trying is the following:

Code: Select all

            String path = getJavaPath();
            String output = "";

            if (path.Length > 0)
            {
                var proc = new Process
                {
                    StartInfo = new ProcessStartInfo
                    {
                        FileName = path,
                        Arguments = "-version",
                        UseShellExecute = false,
                        RedirectStandardOutput = true,
                        CreateNoWindow = true
                    }
                };

                proc.Start();
                while (!proc.StandardOutput.EndOfStream)
                    output += proc.StandardOutput.ReadLine();
            }
If anyone has tried this before and gotten it to work, then I would really appreciate some tip about this.
Been trying different methods all night but can't seem to get it right (rhymes lol).

Anyway thanks in advance :)
"The best place to hide a tree, is in a forest"

User avatar
z3r0aCc3Ss
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 700
Joined: 23 Jun 2009, 16:00
14
Contact:

Re: C#.Net Checking for Java

Post by z3r0aCc3Ss »

This might be helpful:

Code: Select all

http://mdb-blog.blogspot.in/2010/09/c-check-if-programapplication-is.html
Beta tester for major RATs, all kinds of stealers and keyloggers.
Learning NMAP

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Re: C#.Net Checking for Java

Post by ayu »

z3r0aCc3Ss wrote:This might be helpful:

Code: Select all

http://mdb-blog.blogspot.in/2010/09/c-check-if-programapplication-is.html
Nice thanks! :)

I will use this as a backup solution.
I still want my method to work ^^ (It should be rather easy but it just doesn't work! >_<)
"The best place to hide a tree, is in a forest"

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Re: C#.Net Checking for Java

Post by ayu »

oh lol .... solved it now, and it was a really stupid error ^^.
Turns out Java.exe outputs EVERYTHING to StandardError instead of StandardOutput, so the following code works:

Code: Select all

            String path = getJavaPath();
            String output = "";

            if (path.Length > 0)
            {
                var proc = new Process
                {
                    StartInfo = new ProcessStartInfo
                    {
                        FileName = "java",
                        Arguments = "-version",
                        UseShellExecute = false,
                        RedirectStandardError = true,
                        CreateNoWindow = true
                    }
                };

                proc.Start();
                while (!proc.StandardError.EndOfStream)
                    output += proc.StandardError.ReadLine();
            }
"The best place to hide a tree, is in a forest"

User avatar
z3r0aCc3Ss
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 700
Joined: 23 Jun 2009, 16:00
14
Contact:

Re: C#.Net Checking for Java

Post by z3r0aCc3Ss »

:D
FTW +1...
Beta tester for major RATs, all kinds of stealers and keyloggers.
Learning NMAP

Post Reply