Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start program in user folder without knowing user name

I have no idea if I can just run this code and it will work but here:

public void actionPerformed(ActionEvent e) {
        try
        {
        Runtime rt = Runtime.getRuntime();
        Process p = rt.exec("c:\\Users\\Toby\\AppData\\Roaming\\.minecraft\\minecraft.exe");
        }

        catch(Exception a)
        {

        }
    }

This is linked to a button, and it launches the minecraft launcher. If I want to give it to my friends, what do I have to do so that it doesn't look for the user 'Toby', but instead looks for their home folder? Sorry if its confusing!


1 Answers

I think you're looking for the user.home property. There's a list of properties available here: http://www.mindspring.com/~mgrand/java-system-properties.htm

So, your code would be changed to:

Process p = rt.exec(System.getProperty("user.home") + \\AppData\\Roaming\\.minecraft\\minecraft.exe");
like image 176
jefflunt Avatar answered Jan 26 '26 11:01

jefflunt