Determining common start menu/startup folder

snarfblam

Mega-Ultra Chicken
Joined
Jun 10, 2003
Messages
1,832
Location
USA
User Rank
*Expert*
The System.Environment.GetFolderPath() function can be used to get a users startup or start menu folder, for example:

C:\Windows\Documents and Settings\Freddie\StartMenu
-or -
C:\Windows\Profiles\Frank\StartMenu\Startup

How can you get the common start menu or startup folder? As in...

C:\Windows\Documents and Settings\All Users\StartMenu


(I already checked... There is no option for common start menu or common documents and settings or common startup.)
 
Theres no direct way of getting the other folders in the but u can always getthe parent folder of the "CommonApplicationData" and then get all the subdirectories in that folder or just check (Directory.Exists) to see if u can find the folder u are looking for
//C# code
MessageBox.Show(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData));
string dir = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
dir = Directory.GetParent(dir).FullName;
MessageBox.Show(dir);
string[] dirs = Directory.GetDirectories(dir);
string subdirs = "";
foreach(string s in dirs)
subdirs +="\n" + s;
MessageBox.Show(subdirs);
 
You should always read this information from HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders. You cant simply assume the location of directories like these.
 
...hence the use of Environment.GetFolder and the existance of this thread.

Is there anyway to determine the path of %ALLUSERSPROFILE%?

I can get the path for common program files and common application data. I need to common start menu. Are these all guaranteed to be in that same parent directory? I know that each users app data and start menu and program files are NOT guaranteed to be in the same folder (you can easily change the locations of these folders with Tweak UI).
 
Last edited by a moderator:
You can find it with a simple Win32 API call to [api]GetEnvironmentVariable[/api].

Code:
Public Class Win32API
     DWORD GetEnvironmentVariable(
          LPCTSTR lpName,
          LPTSTR lpBuffer,
          DWORD nSize
     );

     Public Declare Unicode Function GetEnvironmentVariableW Lib "kernel32.dll" _
          (ByVal name As String, ByVal buffer As System.Text.StringBuilder, ByVal size As Integer) As Integer
End Class

Code:
Dim name As String = "ALLUSERSPROFILE"
Dim buffer As System.Text.StringBuilder = New System.Text.StringBuilder(32767)

Dim returnValue As Integer = Win32API.GetEnvironmentVariableW(name, buffer, buffer.Capacity)

MessageBox.Show("Return value: " & returnValue.ToString())
MessageBox.Show(buffer.ToString())
 
What an amazingly simple solution. Dont know why I didnt see that myself... thanks
 
Back
Top