Need to Get Start Menu Paths in Java

Using java, I would like some code to get me the paths for: 1) Start menu for the current user 2) Start menu for all users

I need an answer for WinXP and Win7. So I hope there is a general answer that can get me both.

+3
source share
5 answers

Well, I understood the solution, but maybe someone else has a more decent answer.

I plan to do something like "Runtime.getRuntime (). Exec (command);" and the command will be "reg query" to query the following registry keys:

: HKEY_CURRENT_USER\ \Microsoft\Windows\CurrentVersion\Explorer\ Folders\ ""

: HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\ Folders\ ""

Win7 WinXP. - , .

+2

, DLL Windows API:

  • SHGetFolderPath (NULL, CSIDL_PROGRAMS, NULL, SHGFP_TYPE_CURRENT, &szPathBuffer)
  • SHGetFolderPath(NULL, CSIDL_COMMON_PROGRAMS, NULL, SHGFP_TYPE_CURRENT, &szPathBuffer)

"", CSIDL_STARTMENU CSIDL_COMMON_STARTMENU.
: CSIDL.

Windows Vista , SHGetKnownFolderPath SHGetFolderPath.

JNA library Windows API , Java.

+4

"" API vbs.

Java Wrapper .

// Install Start Menu
WindowsUtils.installStartMenuItem(WindowsUtils.SPECIALFOLDER_Programs,"my_start_menu", "explorer.exe", "http://www.google.es","Acceso directo a google");

// Uninstall Start Menu
WindowsUtils.uninstallStartMenuItem(WindowsUtils.SPECIALFOLDER_Programs, "my_start_menu");
0

public class VBSUtils {

  public static String SF_ALLUSERSDESKTOP    = "AllUsersDesktop";
  public static String SF_ALLUSERSSTARTMENU  = "AllUsersStartMenu";
  public static String SF_ALLUSERSPROGRAMS   = "AllUsersPrograms";
  public static String SF_ALLUSERSSTARTUP    = "AllUsersStartup";
  public static String SF_DESKTOP            = "Desktop";
  public static String SF_FAVORITES          = "Favorites";
  public static String SF_MYDOCUMENT         = "MyDocuments";
  public static String SF_PROGRAMS           = "Programs";
  public static String SF_RECENT             = "Recent";
  public static String SF_SENDTO             = "SendTo";
  public static String SF_STARTMENU          = "StartMenu";

  private VBSUtils() {  }

  public static String getSpecialFolder(String folder) {
    String result = "";
    try {
        File file = File.createTempFile("realhowto",".vbs");
        file.deleteOnExit();
        FileWriter fw = new java.io.FileWriter(file);

        String vbs = "Set WshShell = WScript.CreateObject(\"WScript.Shell\")\n"
                     + "wscript.echo WshShell.SpecialFolders(\"" + folder + "\")\n"
                     + "Set WSHShell = Nothing\n";

        fw.write(vbs);
        fw.close();
        Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
        BufferedReader input =
            new BufferedReader
              (new InputStreamReader(p.getInputStream()));
        result = input.readLine();
        input.close();
    }
    catch(Exception e){
        e.printStackTrace();
    }
    return result;
  }

      public static void main(String[] args){
          System.out.println(VBSUtils.getSpecialFolder(VBSUtils.SF_ALLUSERSSTARTMENU));
        System.out.println(VBSUtils.getSpecialFolder(VBSUtils.SF_ALLUSERSDESKTOP));
        System.out.println(VBSUtils.getSpecialFolder(VBSUtils.SF_DESKTOP));
        System.out.println(VBSUtils.getSpecialFolder(VBSUtils.SF_PROGRAMS));
        //System.out.println(VBSUtils.getSpecialFolder(VBSUtils.SF_STARTUP));
      }
    }
0

System.getProperty("user.home") + "/Start Menu/Programs" "" .

It worked on Windows 7 and Windows 10. I tried this because in order to get the user's desktop, I only had to make a call System.getProperty("user.home") + "/Desktop". I realized that it can work for the Start menu, and it seems that it did a great job. I can delete and write files to the Start menu as I can from the desktop. Whether this is the right way to do something like this or not, I have no idea. But I'm just sharing what worked for me.

0
source

All Articles