Reputation:
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!
Upvotes: 3
Views: 165
Reputation: 33954
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");
Upvotes: 5
Reputation: 6783
If you want to keep consistency with other version of Windows, I would suggest using the System.getenv("APPDATA")
instead of adding to System.getProperty("user.home")
because Roaming folder is not present in older version of Windows
So your code would change to something like this:
Process p = rt.exec(System.getenv("APPDATA") + ".minecraft\\minecraft.exe")
Upvotes: 4
Reputation: 33534
Try System.getProperty("user.home")
String mhome = System.getProperty("user.home"))+"";
public void actionPerformed(ActionEvent e) {
try
{
Runtime rt = Runtime.getRuntime();
Process p = rt.exec(mhome+"\\AppData\\Roaming\\.minecraft\\minecraft.exe");
}
catch(Exception a)
{
}
}
Upvotes: 0