Leaders snarfblam Posted February 8, 2005 Leaders Posted February 8, 2005 The System.Environment.GetFolderPath() function can be used to get a user's 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.) Quote [sIGPIC]e[/sIGPIC]
twistedm1nd Posted February 9, 2005 Posted February 9, 2005 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); Quote
*Gurus* Derek Stone Posted February 10, 2005 *Gurus* Posted February 10, 2005 You should always read this information from HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders. You can't simply assume the location of directories like these. Quote Posting Guidelines
Leaders snarfblam Posted February 13, 2005 Author Leaders Posted February 13, 2005 (edited) ...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). Edited February 13, 2005 by snarfblam Quote [sIGPIC]e[/sIGPIC]
*Gurus* Derek Stone Posted February 14, 2005 *Gurus* Posted February 14, 2005 You can find it with a simple Win32 API call to [api]GetEnvironmentVariable[/api]. 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 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()) Quote Posting Guidelines
Administrators PlausiblyDamp Posted February 14, 2005 Administrators Posted February 14, 2005 You could also use the Environment class Label1.Text = Environment.GetEnvironmentVariable("ALLUSERSPROFILE") Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
*Gurus* Derek Stone Posted February 14, 2005 *Gurus* Posted February 14, 2005 Well gosh darn... I reckon that's a much better idea. :) [edit]Not half as fun though...[/edit] Quote Posting Guidelines
Leaders snarfblam Posted February 14, 2005 Author Leaders Posted February 14, 2005 What an amazingly simple solution. Don't know why I didn't see that myself... thanks Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.