• 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

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

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.

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
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

    • The GEEKOM A8 mini PC is 20% off (lower than Prime Day pricing) plus Huge Storewide Sale by Steven Parker GEEKOM is back with a deal on a variant of its A8 Mini PC powered by AMD's Ryzen 7 8945HS, which came out in 2024 with a TDP of just 45W, with a base clock of 3.8 GHz and a Turbo Boost of 4.9 GHz; although we never reviewed this variant, we did check out the Ryzen 9 version. As a reminder of what you get, below are the specifications for this Mini PC. GEEKOM A8 Dimensions 112.4 mm x 112.4 mm x 37 mm Weight 450g CPU Ryzen 7 8745HS (8 cores, 16 threads, 16MB L3 cache, 3.8 - 4.9 GHz, TDP: 45 W) cTDP: 35-54W (Default 45W) Graphics AMD Radeon™ 780M Graphics 12 RDNA 3 Graphics Cores 2700MHz 768 shading units / stream processors (12 CUs), 48 texture mapping units, and 32 ROPs NPU XDNA architecture (Up to 16 NPU TOPS) Memory 16GB Dual-channel Crucial DDR5-5600MT/s SODIMM (up to 64GB) Storage 1TB NVMe M.2 (PCIe Gen 4.0 x4) Operating System Windows 11 Pro Bluetooth Bluetooth v5.2 Wireless LAN Wi-Fi 6E Kensington Lock No SD Card reader Yes (left side) Adapter 120W, 6.32A, 19V Power Adapter Front I/O Ports 2 x USB 3.2 Gen 2 Type-A 1 x 3.5mm front stereo headset jack Rear I/O Ports 1 x USB 3.2 Gen 2 Type-A 1 x USB 4 Gen 3 Type-C with Power delivery up to 15W (5V 3A) 1 x USB 3.2 Gen 2 Type-C 1 x USB 2.0 Type-A 2 x HDMI 2.0b 1 x 2.5G RJ45 LAN 1 x DC-in Deal Price $519 (buying links below) GEEKOM has two configurations of the A8, with the only difference being the slightly less-powerful Ryzen 7 CPU with half the storage (1TB) and DDR5 memory (16GB). This knocks $350 off the price compared to the $999 Ryzen 9 configuration. In both instances, a Windows 11 Pro license is also pre-loaded. As I said previously, this appears to be an update on the A7 with the only difference being the newer CPU. The packaging has changed quite a bit from the A7. Instead of dark colors, now the box is completely white, and the foam cushion has been replaced by a cardboard mould that the A8 sits in, above a small envelope that contains a thank you card and booklet that has guidance on all of the controls, how to access the A8 to swap out the SSD or memory, and safety information in several European languages. Upon removing the cardboard mould, you can find another cardboard compartment that contains the power lead, HDMI cable, VESA plate, and a bag of screws. What’s In The Box 1 x A8 Mini PC 1 x Power Adapter 1 x HDMI Cable 1 x VESA plate and bag of screws 1 x Envelope with booklet and Thank you card Unlike the A7, the VESA mount option is back with the A8. In short, you have everything you need to get started. All products sold by GEEKOM receive a 3-year free Warranty from the date you receive the product. If needed, you can RMA or return locally relative to your region (the U.S. has a U.S. warehouse, mainland E.U. has a German warehouse). GEEKOM A8 at GEEKOM U.S. for $519 was $649 (20% off) GEEKOM A8 at GEEKOM U.K. for £503 was £629 (20% off) GEEKOM A8 at GEEKOM CA for $735.20 was $919 (20% off) Use coupon code NWGKA820 when checking out. This flash deal expires on July 2. Next up is the highest savings on the A7 Max series of Mini PC in the Spring Sale. The GEEKOM [2026 Edition] A7 MAX with AMD Ryzen 9 7940HS, 16GB DDR5, and 1TB SSD. Operating System: Windows 11 Pro CPU Model: Ryzen 9 7940HS CPU Speed: 5.2 GHz Cache Size: 24 MB Graphics Card Description: Integrated Graphics Coprocessor: AMD Radeon 780M Memory Storage Capacity: 16GB DDR5 SSD: 1 TB We reviewed this Mini PC back in January, and praised it for its modern internals like a dedicated NPU and DDR5 memory; as such, it is more than capable of keeping up with today's offerings of Mini PC on the market. GEEKOM A7 Max at GEEKOM U.S. for $587 (was $699) 16% off GEEKOM A7 Max at GEEKOM U.K. for £551 was £689 (20% off) Use coupon code NWGKA7MAX when checking out. This flash deal expires on July 2. Huge Summer Sale If the above deals don't tickle your fancy, from today, there are deep discounts on a range of other GEEKOM products. From June 15 to June 30, the GEEKOM Official Store will be running its Summer Sale, with discounts starting from 15% off across the entire lineup, up to 50%! This is their biggest promotion of the year so far, offering pricing that is even lower than select Prime Day deals. You can check out the discounts at the dedicated Summer Sale landing pages below. GEEKOM U.S. Summer Sale GEEKOM U.K. Summer Sale What's more, all products from GEEKOM receive a 3-year free Warranty from the date you receive the product. If needed, you can RMA or return locally relative to your region (the U.S. has a U.S. warehouse, mainland E.U. has a German warehouse, the U.K. has a U.K. warehouse, Australia has an AU warehouse). While the Summer Sale ends on June 30, deals on the A8 and A7 Max will remain active until July 2.
    • Oh man, the memories.
    • Affinity by Canva 3.2.2.4557 by Razvan Serea Affinity by Canva is a free, all-in-one creative app combining vector design, photo editing, and page layout in a single platform. Originally developed by Serif, it’s now under Canva, offering professional-grade tools without subscriptions. Users get full access to Pixel, Vector, and Layout studios, plus ongoing updates. Designed for Mac and Windows, it empowers designers, illustrators, and content creators to work faster, smarter, and more creatively than ever before. Affinity is a unified, high-performance design platform combining vector, raster, and layout workflows. It offers fully non-destructive editing, advanced curve and shape manipulation, artboards, symbols, and seamless integration of pixel and vector content. The photo engine supports RAW editing, compositing, retouching, and batch processing with macro automation. Layout tools include long-form document support, typographic precision, navigational elements, CMYK-ready print, and Data Merge. Canva AI Studio adds generative tools (Fill, Expand, Edit), Depth Map, Super Resolution, and advanced portrait effects, accessible via Canva Pro or higher. Broad file compatibility and customizable workspaces ensure professional-grade efficiency. Advanced AI features like Generative Fill and Expand are unlocked in Affinity through the Canva AI Studio for users with a Canva premium plan (Pro, Business, Enterprise, or Education). Affinity is truly free. Every tool in the Pixel, Vector, and Layout studios is fully accessible, along with all customization and export options—no limits, no payments required. The app also receives free updates with new features and improvements. Your creativity remains yours. Affinity stores all your work locally on your device. Canva does not use any Affinity content to train AI or develop features, including anything created with Canva AI tools within Affinity. If you export or upload your work to Canva, you remain in full control. Data preferences can be reviewed or updated at any time in your Canva account settings. Why is Affinity free? Curious how this is possible? Here’s the philosophy behind it and how it works. Note: A free Canva account is required to use Affinity. Your account gives access to Affinity along with other Canva products and features. Download: Affinity 3.2.2.4557 | ARM64 | ~600.0 MB (Freeware) Links: Affinity Website | macOS | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • Week One Done
      Jeroen Wilms earned a badge
      Week One Done
    • Week One Done
      rolfus earned a badge
      Week One Done
    • One Month Later
      Leroy Jethro Gibbs earned a badge
      One Month Later
    • Conversation Starter
      flexorcist earned a badge
      Conversation Starter
    • One Month Later
      AndreaB earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      513
    2. 2
      +Edouard
      205
    3. 3
      PsYcHoKiLLa
      136
    4. 4
      ATLien_0
      88
    5. 5
      Steven P.
      85
  • Tell a friend

    Love Neowin? Tell a friend!