• 0

C#: Get path of Start Menu programs (All USERS)


Question

hi guys

does anyone know how can i get the path of the start menu under All Users (X:\Documents and Settings\All Users\Start Menu\Programs) ?

i tried :

DirectoryInfo di = new DirectoryInfo(System.Environment.G? etFolderPath(Environment.SpecialFo? lder.Programs));

but that only gives the Path for current user. How can i get to the All Users start menu?

12 answers to this question

Recommended Posts

  • 0

The built-in .Net methods are underdeveloped, IMO. Use WinAPI.

See here for the function SHGetSpecialFolderPath, and a link to the list of CSIDL's you can use.

http://msdn2.microsoft.com/en-us/library/ms647816.aspx

Here's the function import and a sample on how to use it:

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

const int CSIDL_PROGRAMS = 2;  // \Windows\Start Menu\Programs
StringBuilder path = new StringBuilder(260);
SHGetSpecialFolderPath(IntPtr.Zero, path, CSIDL_PROGRAMS, false);
// path.ToString() should now hold the path

Here's the full list of CSIDL's from ShlObj.h

const int CSIDL_DESKTOP 					= 0x0000;		// <desktop>
const int CSIDL_INTERNET					= 0x0001;		// Internet Explorer (icon on desktop)
const int CSIDL_PROGRAMS					  = 0x0002;		// Start Menu\Programs
const int CSIDL_CONTROLS					  = 0x0003;		// My Computer\Control Panel
const int CSIDL_PRINTERS					  = 0x0004;		// My Computer\Printers
const int CSIDL_PERSONAL					  = 0x0005;		// My Documents
const int CSIDL_FAVORITES				 	= 0x0006;		// <user name>\Favorites
const int CSIDL_STARTUP				   	= 0x0007;		// Start Menu\Programs\Startup
const int CSIDL_RECENT					  = 0x0008;		// <user name>\Recent
const int CSIDL_SENDTO					  = 0x0009;		// <user name>\SendTo
const int CSIDL_BITBUCKET				   = 0x000a;		// <desktop>\Recycle Bin
const int CSIDL_STARTMENU				   = 0x000b;		// <user name>\Start Menu
const int CSIDL_MYDOCUMENTS				 = CSIDL_PERSONAL; //  Personal was just a silly name for My Documents
const int CSIDL_MYMUSIC					 = 0x000d;		// "My Music" folder
const int CSIDL_MYVIDEO					 = 0x000e;		// "My Videos" folder
const int CSIDL_DESKTOPDIRECTORY			= 0x0010;		// <user name>\Desktop
const int CSIDL_DRIVES					  = 0x0011;		// My Computer
const int CSIDL_NETWORK					 = 0x0012;		// Network Neighborhood (My Network Places)
const int CSIDL_NETHOOD					 = 0x0013;		// <user name>\nethood
const int CSIDL_FONTS					   = 0x0014;		// windows\fonts
const int CSIDL_TEMPLATES				   = 0x0015;
const int CSIDL_COMMON_STARTMENU			= 0x0016;		// All Users\Start Menu
const int CSIDL_COMMON_PROGRAMS			 = 0x0017;		// All Users\Start Menu\Programs
const int CSIDL_COMMON_STARTUP			  = 0x0018;		// All Users\Startup
const int CSIDL_COMMON_DESKTOPDIRECTORY	 = 0x0019;		// All Users\Desktop
const int CSIDL_APPDATA					 = 0x001a;		// <user name>\Application Data
const int CSIDL_PRINTHOOD				   = 0x001b;		// <user name>\PrintHood
const int CSIDL_LOCAL_APPDATA			   = 0x001c;		// <user name>\Local Settings\Applicaiton Data (non roaming)
const int CSIDL_ALTSTARTUP				  = 0x001d;		// non localized startup
const int CSIDL_COMMON_ALTSTARTUP		   = 0x001e;		// non localized common startup
const int CSIDL_COMMON_FAVORITES			= 0x001f;
const int CSIDL_INTERNET_CACHE			  = 0x0020;
const int CSIDL_COOKIES					 = 0x0021;
const int CSIDL_HISTORY					 = 0x0022;
const int CSIDL_COMMON_APPDATA			  = 0x0023;		// All Users\Application Data
const int CSIDL_WINDOWS					 = 0x0024;		// GetWindowsDirectory()
const int CSIDL_SYSTEM					  = 0x0025;		// GetSystemDirectory()
const int CSIDL_PROGRAM_FILES			   = 0x0026;		// C:\Program Files
const int CSIDL_MYPICTURES				  = 0x0027;		// C:\Program Files\My Pictures
const int CSIDL_PROFILE					 = 0x0028;		// USERPROFILE
const int CSIDL_SYSTEMX86				   = 0x0029;		// x86 system directory on RISC
const int CSIDL_PROGRAM_FILESX86			= 0x002a;		// x86 C:\Program Files on RISC
const int CSIDL_PROGRAM_FILES_COMMON		= 0x002b;		// C:\Program Files\Common
const int CSIDL_PROGRAM_FILES_COMMONX86	 = 0x002c;		// x86 Program Files\Common on RISC
const int CSIDL_COMMON_TEMPLATES			= 0x002d;		// All Users\Templates
const int CSIDL_COMMON_DOCUMENTS			= 0x002e;		// All Users\Documents
const int CSIDL_COMMON_ADMINTOOLS		   = 0x002f;		// All Users\Start Menu\Programs\Administrative Tools
const int CSIDL_ADMINTOOLS				  = 0x0030;		// <user name>\Start Menu\Programs\Administrative Tools
const int CSIDL_CONNECTIONS				 = 0x0031;		// Network and Dial-up Connections
const int CSIDL_COMMON_MUSIC				= 0x0035;		// All Users\My Music
const int CSIDL_COMMON_PICTURES			 = 0x0036;		// All Users\My Pictures
const int CSIDL_COMMON_VIDEO				= 0x0037;		// All Users\My Video
const int CSIDL_RESOURCES				   = 0x0038;		// Resource Direcotry
const int CSIDL_RESOURCES_LOCALIZED		 = 0x0039;		// Localized Resource Direcotry
const int CSIDL_COMMON_OEM_LINKS			= 0x003a;		// Links to All Users OEM specific apps
const int CSIDL_CDBURN_AREA				 = 0x003b;		// USERPROFILE\Local Settings\Application Data\Microsoft\CD Burning
const int CSIDL_COMPUTERSNEARME			 = 0x003d;		// Computers Near Me (computered from Workgroup membership)
const int CSIDL_FLAG_CREATE				 = 0x8000;		// combine with CSIDL_ value to force folder creation in SHGetFolderPath()
const int CSIDL_FLAG_DONT_VERIFY			= 0x4000;		// combine with CSIDL_ value to return an unverified folder path
const int CSIDL_FLAG_DONT_UNEXPAND		  = 0x2000;		// combine with CSIDL_ value to avoid unexpanding environment variables
const int CSIDL_FLAG_NO_ALIAS			   = 0x1000;		// combine with CSIDL_ value to insure non-alias versions of the pidl
const int CSIDL_FLAG_PER_USER_INIT		  = 0x0800;		// combine with CSIDL_ value to indicate per-user init (eg. upgrade)

Note that this was quickly converted from the C++ headers to C#, so there may be simple formatting errors, but all of the data is correct.

Edited by jimbo11883
  • 0

Environment.GetEnvironmentVariable("ALLUSERSPROFILE")

return a string "DRIVE:\Documents and Settings\All Users" (from wikipedia), from there you should beable to get to the StartMenu\Programs

It doesnt work for me but im on Vista, all i get is an hidden folder called ProgramData.It might work on XP.

if not then switch "ALLUSERSPROFILE" with "HOMEDRIVE" and you will get just the drive windows is install on example "C:\" from there you can work your way to where you want to go.

Edited by Doli
  • 0
  On 27/01/2010 at 15:41, garethevans1986 said:

Dude this is like 2 years old!

yeah i know, but google found it when i was searching for this solution....

the code that i sent are only usable if you're looking for the user folders, if you need the Common folders, read this:

http://www.codeproject.com/KB/winsdk/SpecialFolders.aspx

  • 0
  On 27/01/2010 at 11:38, Tufo said:

I know its a late reply, but for ppl that find this post on google (like me) its quite simple to find the start menu folder:

String startMenuPath = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu);

That returns the path for the current user's start menu startup.

  On 27/01/2010 at 15:41, garethevans1986 said:

Dude this is like 2 years old!

He apologized for the late reply and contributed something, what's the problem?

Thanks Tufo, I'm just working through the same problem. I think Jimbo's method is probably most reliable.

  • 0

99.9% of thread being replied to after being "dead" for 2+ years are either troll threads or spammers....

Granted, like you said this poster posted something relevant!

GE

  • 0

This thread may be 3 years old but no one has posted the correct answer yet.

Typically you would use

Environment.GetFolderPath

, but there is no constant defined for it.

Here is the correct solution using a Win32 API:

  class Program
    {
        [DllImport("shell32.dll")]
        static extern bool SHGetSpecialFolderPath(IntPtr hwndOwner,
           [Out] StringBuilder lpszPath, int nFolder, bool fCreate);
        const int CSIDL_COMMON_STARTMENU = 0x16;  // \Windows\Start Menu\Programs

        static void Main(string[] args)
        {
            StringBuilder path = new StringBuilder(260);
            SHGetSpecialFolderPath(IntPtr.Zero, path, CSIDL_COMMON_STARTMENU, false);
            string s = path.ToString();
        }
    }

  • 0
  Quote
but there is no constant defined for it
Sure there is; in .NET 4 :)

Just like with registry access, the .NET implementation of the FolderPath APIs is lacking through version 3.5 SP1. However, starting with .NET 4.0, you can do the following:

Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu)

Edit: the CODE tags screw up the character casing a little bit; the "s" should be capitalized

Edit 2: WTF, it's impossible to capitalize all three parts of that word anywhere in a forum post. Weird.

It would be nice if they would consider community contribution to the BCL for simple things like this. It's just an enum value and we shouldn't have to wrap 10 year-old APIs in P/Invoke (CSIDL_COMMON_STARTMENU has been available natively starting with XP). Actually, on closer look, it appears this was even defined in Windows 2000.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Google Chrome 137.0.7151.69 (offline installer) by Razvan Serea The web browser is arguably the most important piece of software on your computer. You spend much of your time online inside a browser: when you search, chat, email, shop, bank, read the news, and watch videos online, you often do all this using a browser. Google Chrome is a browser that combines a minimal design with sophisticated technology to make the web faster, safer, and easier. Use one box for everything--type in the address bar and get suggestions for both search and Web pages. Thumbnails of your top sites let you access your favorite pages instantly with lightning speed from any new tab. Desktop shortcuts allow you to launch your favorite Web apps straight from your desktop. Chrome has many useful features built in, including automatic full-page translation and access to thousands of apps, extensions, and themes from the Chrome Web Store. Google Chrome is one of the best solutions for Internet browsing giving you high level of security, speed and great features. Important to know! The offline installer links do not include the automatic update feature. Google Chrome 137.0.7151.69 changelog: [N/A][420636529] High CVE-2025-5419: Out of bounds read and write in V8. Reported by Clement Lecigne and Benoît Sevens of Google Threat Analysis Group on 2025-05-27. This issue was mitigated on 2025-05-28 by a configuration change pushed out to Stable across all Chrome platforms. [$1000][409059706] Medium CVE-2025-5068: Use after free in Blink. Reported by Walkman on 2025-04-07 Google is aware that an exploit for CVE-2025-5419 exists in the wild. Download web installer: Google Chrome Web 32-bit | Google Chrome 64-bit | Freeware Download: Google Chrome Offline Installer 64-bit | 128.0 MB Download: Google Chrome Offline Installer 32-bit | 115.0 MB Download page: Google Chrome Portable Download: Google Chrome MSI Installers for Windows (automatic update) View: Chrome Website | Release Notes Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Last night I watched "I, Robot" movie: https://www.youtube.com/watch?v=7Dlo-VB0-HI The day they put AI into Robots is our END... I really scare from that day!!
    • This site is just old men ranting at clouds. Neowin knows its audience.
    • That's nice and all. but I generally just stick with Lutris paired with 'ge-proton' (which gets updated fairly often (June 1st was last update) as the 'ge-proton' entry in Lutris uses stuff here... https://github.com/GloriousEggroll/proton-ge-custom/releases ) and the like to play my games. p.s. if a person wants to stick with a specific version from that link you can download a specific version and extract it to "~/.local/share/lutris/runners/proton/". then select it in Lutris options on game shortcut is the basic idea. because by default the standard 'ge-proton' entry will automatically get updated which can occasionally cause issues even though it's usually fine. but manually setting it on a specific version will prevent the standard updates on 'ge-proton' from messing with it on a particular game you may have issues with if that gets updated etc. one good example of the 'ge-proton' updates messing with a game in particular is the offline version of RDR2 1491.50 as I setup a specific version there and after removing the 'vulkan-1 (native)' entry in 'Wine configuration' on 'RDR2.exe' entry (if you don't remove this the game won't start up) is when the 'ge-proton' updates, it will restore that 'vulkan-1 (native)' entry and prevent the game from working. you can always remove the entry on the RDR2.exe in Wine configuration specifically after updates, but doing that everytime that updates will get old quickly. hence, keeping it on a specific GE Proton version stops me from having to mess with it as then you just adjust it once and you are done with it. also, when using 'bat' files to start a game (like Hitman: WoA for example using Peacock etc) I had some issues with GE Proton after '9-27', so I got the game locked to '9-27' (April 1st) instead of the newer ones (10-1 etc).
    • Sam Altman says AI could soon help with discovering new knowledge by Hamid Ganji OpenAI is currently at the forefront of developing powerful AI models, while its ChatGPT product is rewriting our traditional way of looking for new information. The company's CEO, Sam Altman, now says AI could even help humans discover new knowledge. He also described AI agents as junior employees. Speaking at the Snowflake Summit 2025, Altman boasted that AI agents can act like junior employees, saying, "You hear people that talk about their job now is to assign work to a bunch of agents, look at the quality, figure out how it fits together, give feedback, and it sounds a lot like how they work with a team of still relatively junior employees." OpenAI CEO also added AI agents could help humans discover new knowledge in "limited cases" or "figure out solutions to business problems that are kind of very non-trivial." While the use of AI for scientific discovery is still viewed with skepticism, the technology has proven its capabilities for new discoveries in several cases. For example, the Microsoft Discovery platform, designed for accelerating scientific research and development by AI agents, was recently able to discover a new chemical for cooling data centers in just 200 hours, a process that normally takes years to research and complete by humans. AI firms are also shifting their focus toward developing AI agents capable of performing various tasks. OpenAI recently unveiled Codex, which contains AI agents for helping programmers write and debug code. According to Altman, OpenAI engineers are already using Codex. As AI agents become more intelligent, more employees should be concerned about losing their jobs. Companies have already started replacing some specific roles with AI. For example, Duolingo has replaced its contract workers with AI, while Shopify managers need to provide reasons why AI cannot handle a job before seeking approval for new hires. Via: Business Insider
  • Recent Achievements

    • First Post
      nothin earned a badge
      First Post
    • Enthusiast
      Epaminombas went up a rank
      Enthusiast
    • Posting Machine
      Fiza Ali earned a badge
      Posting Machine
    • One Year In
      WaynesWorld earned a badge
      One Year In
    • First Post
      chriskinney317 earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      188
    2. 2
      snowy owl
      134
    3. 3
      ATLien_0
      130
    4. 4
      Xenon
      119
    5. 5
      +FloatingFatMan
      97
  • Tell a friend

    Love Neowin? Tell a friend!