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



## jal_desai (Jun 27, 2008)

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 (Jun 28, 2008)

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.


```
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.


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

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


----------



## victor_rambo (Jun 28, 2008)

*forum.java.sun.com/thread.jspa?threadID=720313&messageID=4158322


----------



## dheeraj_kumar (Jun 28, 2008)

My computer is not an exe, but Explorer.exe is!!
 try:


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

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



```
""
```

yeah put that in the run box and press enter. It might work with the above function, try it.


----------

