Executing System .exe File of Windows from Core Java

One of my friend was trying to open system calculator and notepad from core Java coding, in windows XP. As he was not getting the solution, after some browsing I found the solution which works very well with xp as well as notepad. I found the trick to be very useful. If we are buliding application for windows, why should we crack our head to build application like calculator and notepad for our system?, which is already very well there in windows.

We have an exec method in Runtime class, which can be used to execute the windows executable file.

For Notepad:

Runtime.getRuntime().exec("C:/WINDOWS/system32/notepad.exe");

For Calculator:

Runtime.getRuntime().exec("C:/WINDOWS/system32/calc.exe");

These command should be in try block

try {
     Runtime.getRuntime().exec("C:/WINDOWS/system32/calc.exe");
 } catch (Exception ex) {
     ex.printStackTrace();
 }

I hope in some kind of project it may help you.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: