Jump to content
Xtreme .Net Talk

Recommended Posts

  • Leaders
Posted

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

[sIGPIC]e[/sIGPIC]
Posted

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

  • Leaders
Posted (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 by snarfblam
[sIGPIC]e[/sIGPIC]
  • *Gurus*
Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...