Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically access All Users Start Menu

Does anyone know how to programmatically access the "All Users" Startup Menu?

In XP, located here:

C:\Documents and Settings\All Users\Start Menu\Programs\Startup

And in Windows 7, located here:

C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup

Specifically, I've got a Setup and Deployment project, and I'd like to put a shortcut to the application in the Startup menu for all users so that the application is start whenever anyone logs in.

EDIT: I'm pretty sure this is where Brian got his answer from.

like image 873
fre0n Avatar asked Feb 24 '10 21:02

fre0n


4 Answers

There is no constant defined for the normal way of Environment.GetFolderPath for the all users start menu, but you can do it this way by using the Win32 API SHGetSpecialFolderPath:

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

    static void Main(string[] args)
    {
        StringBuilder path = new StringBuilder(260);
        SHGetSpecialFolderPath(IntPtr.Zero, path, CSIDL_COMMON_STARTMENU, false);
        string s = path.ToString();
    }
}
like image 59
Brian R. Bondy Avatar answered Oct 25 '22 15:10

Brian R. Bondy


You can also try!

string allUsers=Environment.GetEnvironmentVariable("ALLUSERSPROFILE")+ "\\Start Menu\\Programs";
like image 23
Zain Ali Avatar answered Oct 25 '22 15:10

Zain Ali


In .NET 4 CommonStartMenu was added to the Environment.SpecialFolder enum, so you can use:

Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu)
like image 20
Mike Zboray Avatar answered Oct 25 '22 16:10

Mike Zboray


"All Users" resides in the ALLUSERSPROFILE environment variable:

C:\>dir "%ALLUSERSPROFILE%\Start Menu"
 Volume in drive C is awesome
 Volume Serial Number is 8C57-DB1A

 Directory of C:\Documents and Settings\All Users\Start Menu

12/28/2009  10:27 PM    <DIR>          .
12/28/2009  10:27 PM    <DIR>          ..
12/28/2009  10:01 PM             1,566 Microsoft Update.lnk
02/23/2010  09:57 PM    <DIR>          Programs
12/28/2009  10:27 PM             1,563 Set Program Access and Defaults.lnk
12/28/2009  08:51 PM               398 Windows Catalog.lnk
12/28/2009  08:51 PM             1,507 Windows Update.lnk
               4 File(s)          5,034 bytes
               3 Dir(s)  64,214,460,416 bytes free
like image 21
Seth Avatar answered Oct 25 '22 14:10

Seth