Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Well, I've made a simple program like explorer!. It runs well, but during explore files on my hard disk, It stopped!

The reason is that it can not access to special directory like "Users" directory on system drive C on Windows 7 or 8 OS. Whenever I clicked it on Windows Explorer, "Access Denied" message appeared!

How can I access to those folders and files within C++ code?

Waiting your answers!
Posted

This directory is protected, and, most likely, you really should not access it. It all depends on your goal. Most likely, you need to access the data attributed to a user account or to "all users". If this is so, this is what you have to use:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb762181%28v=vs.85%29.aspx[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/dd378457%28v=vs.85%29.aspx[^].

If you really need to access something which need elevated privileges, you need to run your application "as administrator". Note that having logged as administrator would not be enough. Please see: http://www.sevenforums.com/tutorials/11841-run-administrator.html[^].

In code, all you can do is to create and embed application manifest which requests elevation through UAC dialog in the very beginning:
http://msdn.microsoft.com/en-us/library/bb756929.aspx[^].

Good luck,
—SA
 
Share this answer
 
v2
Comments
DamithSL 17-Jun-14 12:17pm    
5wd!
Sergey Alexandrovich Kryukov 17-Jun-14 12:59pm    
Thank you, Damith.
—SA
WuRunZhe 18-Jun-14 3:29am    
Thank you for your answer! I vote you five.
You can't unless your application has elevated rights - which gives it the permission, but which requires UAE for user approval.

Exactly the same as Windows Explorer: it can't open folders the user is not permitted to access.

You can do what Explorer does: catch the access violation exception and display a message.
 
Share this answer
 
Comments
WuRunZhe 18-Jun-14 3:33am    
Well, I've catched access violation exception message. It is below!

"C:\Users\Default user is not accessible".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900