2

I'm creating a new shorcut within and update of my program on the Start Menu I worked getting the Special Environment variable ALLUSERSPROFILE and it worked for me under XP, it returns the right path, when using it under vista ir returns c:\ProgramData which is useless. Reading the Environment variable StartMenu is also pointless it returns empty string. ( On vista it lies under Windows\Start Menu, in english ,and if the install folder Windows has the default name) Does anyone has an Idea how to get the startmenu directory for the 'All Users". and would it be a generic solution that works under XP and Vista?

3 Answers 3

4

You want CSIDL_COMMON_STARTMENU. This doesn't appear to be defined in the Environment.SpecialFolders enumeration, but you can use the Win32 API via P/Invoke:

[DllImport("shell32.dll")]
static extern bool SHGetSpecialFolderPath(IntPtr hwndOwner,
   [Out] StringBuilder lpszPath, int nFolder, bool fCreate);

int CSIDL_COMMON_STARTMENU = 0x16;
StringBuilder path = new StringBuilder(260);
SHGetSpecialFolderPath(IntPtr.Zero, path, CSIDL_COMMON_STARTMENU, false);

CSIDL_COMMON_STARTMENU (FOLDERID_CommonStartMenu) The file system directory that contains the programs and folders that appear on the Start menu for all users. A typical path is C:\Documents and Settings\All Users\Start Menu. Valid only for Windows NT systems.

7
  • IS this is only valid for NT Systems?
    – jmayor
    Mar 4, 2010 at 17:32
  • @jmayor: Yes. Are you concerned about Windows 98?
    – SLaks
    Mar 4, 2010 at 17:33
  • @jmayor: "Windows NT" is usually used in MSDN to refer to "NT-lineage" operating systems (NT, 2k, XP, Vista, 7), as opposed to "classic" Windows (3.1, 95, 98, Me). Mar 4, 2010 at 17:34
  • I like it, very neat solution, Btw do you know how does it works in the back end, does it looks the data over the registry?. Thanks a lot
    – jmayor
    Mar 4, 2010 at 18:13
  • 1
    You're welcome. A lot of the Win32 APIs you'll see will, in the end, look up data in the registry. It's safer to use the programmatic calls, though, because registry locations can and do change from one Windows release to another. Not always, but sometimes. The SHGetSpecialFolderPath function is documented, supported, and will always return the correct path on a given system. Mar 4, 2010 at 18:16
1

There is no Win32 API needed and no manually registry access. I am using Microsoft Framework 4.0 and can do the following successfully under Win7 and XP:

 Dim diStartMenu As New IO.DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu))
 fiShortCut = New IO.FileInfo(IO.Path.Combine(diStartMenu.FullName, ApplicationTitle & ".lnk"))

this will return the following path for diStartMenu:

C:\ProgramData\Microsoft\Windows\Start Menu

this corresponse fully with the registry value in

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
0

Looking under the registry I found the following key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders there is a value named Common Start Menu that contains the path. It works on vista and XP

1
  • Do not read it off the registry. Use documented APIs instead. These values aren't created until certain Shell APIs are called. You will discover this if you start from a fresh install of Windows and add system restore to your test process. Mar 4, 2010 at 20:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.