How to get the "Programs" special folder for 'All Users'

B

Boaz Ben-Porat

Hi all

I need to find the 'Programs' folder on he Start Menu for 'All Users'. On
standard English Windows XP it is "C:\Documents and Settings\All Users\Start
Menu\Programs", but on other languaghes it is different.

Environment.GetFolderPath(Environment.SpecialFolder.Programs) returns the
Programs folder for current user.

Is there any method to find it for 'All Users' ?

TIA

Boaz Ben-Porat
Milestone Systems A/S
Denmark
 
Z

Zmey

Environment.GetFolderPath(Environment.SpecialFolder.Programs) returns the
Programs folder for current user.

Is there any method to find it for 'All Users' ?

Maybe it's stupid, but you can replace the name of the current user
(in any language) with "All Users"(for any language it's written in
English)
 
N

Nicholas Paldino [.NET/C# MVP]

Boaz,

More than likely, you will have to call the SHGetFolderPath API function
through the P/Invoke layer. It takes a parameter, hToken, which represents
an access token to represent a particular user. You will have to set this
to the user that corresponds to the "all users" directory under "documents
and settings". As for ^which^ user this is, I couldn't say, but I would try
the "Everyone" user first.
 
S

Sheng Jiang[MVP]

you don't need to switch users. use CSIDL_COMMON_PROGRAMS as the folder id.
[DllImport("shfolder.dll", CharSet=CharSet.Auto)]
internal static extern int SHGetFolderPath(IntPtr hwndOwner,
int nFolder, IntPtr hToken, int dwFlags, StringBuilder
lpszPath);

public static void Main(string[] cmd)
{
StringBuilder sbPath = new StringBuilder(260);
SHGetFolderPath(IntPtr.Zero, 0x17, IntPtr.Zero, 0, sbPath);

Console.WriteLine(sbPath.ToString());
}

see also
http://msdn2.microsoft.com/en-us/library/ms649274.aspx
http://support.microsoft.com/kb/306285

--
Sheng Jiang
Microsoft MVP in VC++
Nicholas Paldino said:
Boaz,

More than likely, you will have to call the SHGetFolderPath API function
through the P/Invoke layer. It takes a parameter, hToken, which represents
an access token to represent a particular user. You will have to set this
to the user that corresponds to the "all users" directory under "documents
and settings". As for ^which^ user this is, I couldn't say, but I would try
the "Everyone" user first.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Boaz Ben-Porat said:
Hi all

I need to find the 'Programs' folder on he Start Menu for 'All Users'. On
standard English Windows XP it is "C:\Documents and Settings\All
Users\Start Menu\Programs", but on other languaghes it is different.

Environment.GetFolderPath(Environment.SpecialFolder.Programs) returns the
Programs folder for current user.

Is there any method to find it for 'All Users' ?

TIA

Boaz Ben-Porat
Milestone Systems A/S
Denmark
 
N

Nicholas Paldino [.NET/C# MVP]

Even better!


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Sheng Jiang said:
you don't need to switch users. use CSIDL_COMMON_PROGRAMS as the folder
id.
[DllImport("shfolder.dll", CharSet=CharSet.Auto)]
internal static extern int SHGetFolderPath(IntPtr hwndOwner,
int nFolder, IntPtr hToken, int dwFlags, StringBuilder
lpszPath);

public static void Main(string[] cmd)
{
StringBuilder sbPath = new StringBuilder(260);
SHGetFolderPath(IntPtr.Zero, 0x17, IntPtr.Zero, 0, sbPath);

Console.WriteLine(sbPath.ToString());
}

see also
http://msdn2.microsoft.com/en-us/library/ms649274.aspx
http://support.microsoft.com/kb/306285

--
Sheng Jiang
Microsoft MVP in VC++
in
message news:[email protected]...
Boaz,

More than likely, you will have to call the SHGetFolderPath API function
through the P/Invoke layer. It takes a parameter, hToken, which represents
an access token to represent a particular user. You will have to set
this
to the user that corresponds to the "all users" directory under
"documents
and settings". As for ^which^ user this is, I couldn't say, but I would try
the "Everyone" user first.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Boaz Ben-Porat said:
Hi all

I need to find the 'Programs' folder on he Start Menu for 'All Users'. On
standard English Windows XP it is "C:\Documents and Settings\All
Users\Start Menu\Programs", but on other languaghes it is different.

Environment.GetFolderPath(Environment.SpecialFolder.Programs) returns the
Programs folder for current user.

Is there any method to find it for 'All Users' ?

TIA

Boaz Ben-Porat
Milestone Systems A/S
Denmark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top