Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / July 2007

Tip: Looking for answers? Try searching our database.

StartMenu All users folder in Windows Vista

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
nagar@community.nospam - 09 Jul 2007 23:06 GMT
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
Linda Liu [MSFT] - 10 Jul 2007 12:28 GMT
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.
Sheng Jiang[MVP] - 10 Jul 2007 21:47 GMT
FOLDERID_CommonStartMenu is the known folder id for SHGetKnownFolderPath,
but I doubt a .Net developer would only target Vista

Signature

Sheng Jiang
Microsoft MVP in VC++

> Hi Andrea,
>
[quoted text clipped - 19 lines]
> ==================================================
> Get notification to my posts through email? Please refer to

http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
> ications.
>
[quoted text clipped - 12 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
Linda Liu [MSFT] - 11 Jul 2007 04:30 GMT
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
Sheng Jiang[MVP] - 10 Jul 2007 21:37 GMT
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());
 }

Signature

Sheng Jiang
Microsoft MVP in VC++

> How can I read the contents of the All Users startmenu in Windows
> Vista?
[quoted text clipped - 4 lines]
> Thanks.
> Andrea
Linda Liu [MSFT] - 11 Jul 2007 04:56 GMT
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
nagar@community.nospam - 11 Jul 2007 07:48 GMT
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
Linda Liu [MSFT] - 12 Jul 2007 10:17 GMT
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
Linda Liu [MSFT] - 16 Jul 2007 09:00 GMT
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
Srinivas Patnaik - 17 Jul 2007 05:48 GMT
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
nagar@community.nospam - 18 Jul 2007 07:26 GMT
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

>Hi Andrea,
>
[quoted text clipped - 7 lines]
>Linda Liu
>Microsoft Online Community Support

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.