StartMenu All users folder in Windows Vista

N

nagar

How can I read the contents of the All Users startmenu in Windows
Vista?

Environment.GetFolderPath(Environment.SpecialFolder.StartMenu) returns
just the user specific items.

Thanks.
Andrea
 
L

Linda Liu [MSFT]

Hi Andrea,

I believe that the right way to get the start menu folder for all users on
a Vista machine is to use the Win32 API SHGetKnownFolderPath function.

You may refer to the following link to get more information on the
SHGetKnownFolderPath function.

http://msdn2.microsoft.com/en-us/library/ms647783.aspx

I have tried to use the SHGetKnownFolderPath to get the start menu folder
for all users. Unfortunately, I haven't worked it out until now. If you
work it out using the SHGetKnownFolderPath, please tell me know.

I will go on the research and will get back to you ASAP. I appreciate your
patience!

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Sheng Jiang[MVP]

You can call SHGetFolderPath via p-invoke
[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, 0x16, IntPtr.Zero, 0, sbPath);

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

Sheng Jiang[MVP]

FOLDERID_CommonStartMenu is the known folder id for SHGetKnownFolderPath,
but I doubt a .Net developer would only target Vista
 
L

Linda Liu [MSFT]

Hi Andrea,

After doing some research, I work the problem out.

The key point is that the SHGetKnownFolderPath returns a address of a
pointer to a null-terminated Unicode string that specifies the path of the
known folder.

So we need to define the type of the ppszPath parameter as IntPtr. Note
that we also need to free the resource once it is no longer needed by
calling CoTaskMemFree function. The following is a sample.

Guid FOLDERID_CommonStartMenu = new
Guid("{A4115719-D62E-491D-AA7C-E74B8BE3B067}");

[DllImport("shell32.dll")]
extern static int SHGetKnownFolderPath(ref Guid rfid, int dwFlags, int
hToken,out IntPtr path);
[DllImport("ole32.dll")]
extern static void CoTaskMemFree(IntPtr pv);

IntPtr intPtr;
SHGetKnownFolderPath(ref FOLDERID_CommonStartMenu, 0, 0,out intPtr);

// convert the IntPtr to a string via Marshal.PtrToStringUni
string path = Marshal.PtrToStringUni(intPtr);

// free the resource via CoTaskMemFree
CoTaskMemFree(intPtr);

Hope this helps.
If you have anything unclear, pleae feel free to let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support
 
L

Linda Liu [MSFT]

Hi Sheng,

Thank you for sharing this to us!

I have tried your sample code on my machine and it works well : )

Microsoft Windows Vista introduces new storage scenarios and a new user
profile namespace. To address these new factors, the older system of
referring to standard folders by a CSIDL value has been replaced. As of
Windows Vista, those folders are referenced by a new set of GUID values
called Known Folder IDs.

The CSIDL system and those APIs the make use of CSIDL values are still
supported for compatibility. However, it is not recommended to use them in
any new development.

MSDN document points out that the new ShGetKnownFolderPath function
replaces the old SHGetFolderPath function.

Hope this helps.

Sincerely,
Linda Liu
Microsoft Online Community Support
 
N

nagar

Thanks so much. I'll do some tests.

The strange thing I noticed is that I get an exception when trying to
read the contents of the directory in the startmenu from a standard
user account. That's pretty strange because that information should be
accessible.
I need to get a full list of all the links in the startmenu (therefore
I need to get the all users and the current user start menu contents).

Thanks.
Andrea
 
L

Linda Liu [MSFT]

Hi Andrea,

Thank you for your prompt response.

I performed a test. I log on my Vista machine using a standard user account
and list the files in the start menu folder for all users in my test
application. The result is that I can list all the files in the start menu
folder for all users from a standard user account.

The following is the code in my test.

string path = "get the start menu for all users using the
SHGetKnownFolderPath function";

DirectoryInfo di = new DirectoryInfo(path);
// the fis array contains the names of all the files in the folder
FileInfo[] fis = di.GetFiles();

Is there any difference between your code and mine? If you run your
application as administrator, can you list the files in the start menu
folder for all users?


Sincerely,
Linda Liu
Microsoft Online Community Support
 
L

Linda Liu [MSFT]

Hi Andrea,

How about the problem now?

If the problem is still not solved, please feel free to let me know.

Thank you for using our MSDN Managed Newsgroup Support Service!

Sincerely,
Linda Liu
Microsoft Online Community Support
 
S

Srinivas Patnaik

Hi,
Is thr anyway of getting the path of the virtual store of a known
folder. e.g.
the path of Documents folder is: c:\Users\myUser\Documents
virtual store path for IE7:
c:\Users\myUser\Documents\AppData\Local\Microsoft\Windows\Temporary
Internet Files\Virtualized\C\Users\myUser\Documents.

So, given the known folder, i want to find the virtual store path, the
2nd one.

Regards,
Srini
 
N

nagar

Thanks Linda. It worked fine. I used different code in Windows XP and
Vista to detect the allusers menu.
Once again, thanks a lot for your useful help.
Andrea
 

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