私はすべてのユーザーのショートカット ディレクトリへの書き込みに取り組んでおり、動作していると思いますが、パスを取得する方法が正しくないようです。そして、すべてのユーザーのパスが存在するかどうか、またはより良い方法があるかどうかを確認する正しい方法であるかどうかはわかりません。これは、windows xp - windows 8. および windows server 2000 - 2012 で動作できると想定されています。コードは次のとおりです。
int pathOne = 0;
int pathTwo = 0;
String allUserPath = "";
File sourceOne = new File("C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\");
if (sourceOne.exists())
{
pathOne = 1;
}
File sourceTwo = new File("C:\\Documents and Settings\\All Users\\Start Menu\\");
if (sourceTwo.exists())
{
pathTwo = 1;
}
if (pathOne == 1 && pathTwo == 0)
{
allUserPath = "C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs";
}
if (pathTwo == 1 && pathOne== 0)
{
allUserPath = "C:\\Documents and Settings\\All Users\\Start Menu\\Programs";
}
更新: 調査を行ったところ、コマンド ライン クエリを実行できることがわかりました。
public static final String REG_QRY_CMD="reg query ";
public static final String SHORT_CUT_REG_KEY="HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
String str = REG_QRY_CMD+"\""+
SHORT_CUT_REG_KEY+"\""+ " /v " + "\""+ "Programs" +"\"";
これで、現在のユーザーのプログラム フォルダーにアクセスできます。例 "C:\Documents and Settings\al\Start Menu\Programs" または "E:\Documents and Settings\meg\Start Menu\Programs" 方法はありますか?これをスライスできますか?少なくとも「?:\Documents and Settings\」を取得するには? そうすれば、少なくとも現在のユーザーだけでなく、すべてのユーザーに追加できます。このようにして、推測作業が少なくなり、わずかに良くなります。ありがとうございました