Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to get Start Menu Paths in Java

Using java, I would like some code that could get me the paths for: 1) Start Menu for Current User 2) Start Menu for All User

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

like image 509
James Oravec Avatar asked May 19 '26 12:05

James Oravec


2 Answers

You have no other choice but to write a DLL and call native Windows API:

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

If you really need the root of Start menu, use CSIDL_STARTMENU and CSIDL_COMMON_STARTMENU.
The full list of known folders: CSIDL.

If you target Windows Vista and above, use SHGetKnownFolderPath function instead of SHGetFolderPath.

You can use JNA library to call native Windows API without writing native code yourself but pure Java code.

like image 50
Alexey Ivanov Avatar answered May 22 '26 00:05

Alexey Ivanov


Okay, I figured out a solution, but maybe someone else has a more eligant one.

I plan on doing something like "Runtime.getRuntime().exec(command);" and the command will be a "reg query" to query the following registry keys:

Current User can referenced by: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Start Menu

All users can be referenced by: HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Common Start Menu

These are the same for both Win7 and WinXP. If anyone else knows of a better solution, I'll be happy to look at it too.

like image 38
James Oravec Avatar answered May 22 '26 02:05

James Oravec



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!