How to open "My Computer" through a JAVA code??

Status
Not open for further replies.

jal_desai

In the zone
hi all... i want to open "My Computer" window through a Java Code... i m not able to find the code...

i also wanted to open windows media player through a java code.. and i got success in it.. i used the Process process = Runtime.getRuntimeexec("c:/pro.../../wmplayer.exe"); ... BUT this is possible only if we know the place where the exe is located... and MY COMPUTER is not an exe... i know tht it has a CLSID key which needs to be run in explorer... so can anyone tell me how to run a clsid key from within a JAVA code???

thnks
 

chandru.in

In the zone
I don't think it is possible to open "My Computer" itself as it does not have a path in Windows Operating System. However, if you want to open a specific directory using the Operating System's default file manager, you can try the following code. It works in a completely platform independent manner, unlike the Runtime.exec() method invocation.

Code:
package main;

import java.awt.Desktop;
import java.io.File;
import java.io.IOException;

import javax.swing.filechooser.FileSystemView;

public class Main {
    public static void main(String[] args) throws IOException {
        Desktop desktop = Desktop.getDesktop();
        File dirToOpen = new File("C:\\some_directory");
        desktop.open(dirToOpen);
    }
}
If you want to open the default directory for current user ("My Documents" on Windows and user's home directory on Linux and UNIX), you can use the following code to get a File object for the default directory.

Code:
File defaultDirectory = FileSystemView.getFileSystemView().getDefaultDirectory();
Hope it helped you a bit.

Note: The Desktop class used above is available from Java 6.
 
Last edited:

dheeraj_kumar

Legen-wait for it-dary!
My computer is not an exe, but Explorer.exe is!!
try:

Code:
Process process = Runtime.getRuntimeexec("C:/Windows/Explorer.exe");

and for opening the users/documents and settings folder for any user, run
Code:
""

yeah put that in the run box and press enter. It might work with the above function, try it.
 
Status
Not open for further replies.
Top Bottom