문제

Java를 사용하여 다음 경로를 얻을 수 있는 코드를 원합니다.1) 현재 사용자의 시작 메뉴 2) 모든 사용자를위한 메뉴 시작

WinXP와 Win7 모두에 대한 답변이 필요합니다.따라서 두 가지 모두를 얻을 수 있는 일반적인 답변이 있기를 바랍니다.

도움이 되었습니까?

해결책 2

괜찮아, 나는 해결책을 알아 냈지만, 어쩌면 다른 누군가가 더 많은 eLigant 하나를 가지고있을 것입니다.

"runtime.getruntime ()과 같은 일을 계획합니다. EXEC (명령);"명령은 다음 레지스트리 키를 쿼리하는 명령이 "reg query"가됩니다.

현재 사용자는 HKEY_CURRENT_USER \ Software \ Microsoft \ Windows \ CurrentVersion \ explorer \ 쉘 폴더 \ 시작 메뉴

모든 사용자는 HKEY_LOCAL_MACHINE \ Software \ Microsoft \ Windows \ CurrentVersion \ explorer \ 쉘 폴더 \ 일반 시작 메뉴 에 의해 참조 될 수 있습니다.

이들은 Win7 및 WinXP 모두에서 동일합니다.다른 사람이 더 나은 해결책을 알고 있다면, 나는 그것을 볼 것입니다.

다른 팁

다른 선택의 여지가 없지만 DLL을 작성하고 기본 Windows API를 호출 할 수 있습니다.

내 프로그램에서 나는 간단한 것을 사용했습니다. System.getProperty("user.home") + "/Start Menu/Programs" 이것은 나에게 사용자의 시작 메뉴 폴더를 제공했습니다.

Windows 7과 Windows 10에서 작동했습니다.사용자의 데스크톱을 얻으려면 전화만 하면 되었기 때문에 이것을 시도했습니다. System.getProperty("user.home") + "/Desktop".그래서 시작 메뉴에서도 작동할 수 있다고 생각했고 제대로 작동하는 것 같았습니다.데스크톱에서와 마찬가지로 시작 메뉴에서 파일을 삭제하고 쓸 수 있습니다.이것이 이런 일을 하는 올바른 방법인지 아닌지는 모르겠습니다.하지만 나는 나에게 도움이 된 것을 공유하고 있습니다.

다른 옵션은 VBS API에서 시작 메뉴 항목을 관리하는 것입니다.

나는 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");
.

나는 최근에 이것을 발견했습니다

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));
      }
    }
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top