Solved

Restrict access to a folder

Posted on 2006-06-19
6
690 Views
Last Modified: 2013-11-20
Hi everybody,

I have an MFC application that save some important facts in a folder called "Rma32", how can i prevent that a user access it from windows explorer or My PC icon, I have in my PC a folder "RRUbackups" that when I try to open send  me a message with "ACCESS DENIED"  and how to protect it of a user (that is not administrator) can delete it.
I want to do this always, when my program is running or not.

Best Regards.
0
Comment
Question by:SalvaThor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 22

Expert Comment

by:mahesh1402
ID: 16942139
You can't exactly password protect that way, but you can file encryption to encrypt files n hide them so that noone can access them. You may use components like Alfa File Protector to hide all files in a directory, protect them from any action etc. AFP also tag protection with password, so one needs a password to turn off the protection. It's a component / VC++ library - www.alfasp.com <==


-MAHESH

0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 16942159
another is magic folder : http://www.pc-magic.com/

-MAHESH
0
 
LVL 86

Accepted Solution

by:
jkr earned 250 total points
ID: 16943464
You could remove all the ACLs for that folder except the one for 'admin'. The easiest way would be to spawn 'cacls.exe' for that, e.g.

DWORD ExecuteAndWaitForCompletion   (   LPSTR   pszCmd);

void RestrictAccess(char* psz) {

    char acCmd[MAX_PATH];

    wsprintf(acCmd,"cacls.exe /T /G Administrator:F");

   ExecuteAndWaitForCompletion(acCmd);
}

DWORD ExecuteAndWaitForCompletion   (   LPSTR   pszCmd)
{
   STARTUPINFO         si;
   PROCESS_INFORMATION pi;

   BOOL                bRes;

   DWORD               dwCode  =   0;

   MSG                           msg;

   ZeroMemory  (   &si,    sizeof  (   STARTUPINFO));

   si.cb           =   sizeof  (   STARTUPINFO);
   si.dwFlags      =   STARTF_USESHOWWINDOW;
   si.wShowWindow  =   SW_SHOWNORMAL;

   bRes    =   CreateProcess   (   NULL,
                                   pszCmd,
                                   NULL,
                                   NULL,
                                   TRUE,
                                   NORMAL_PRIORITY_CLASS,
                                   NULL,
                                   NULL,
                                   &si,
                                   &pi
                               );

   while   (   WAIT_OBJECT_0   !=  MsgWaitForMultipleObjects   (   1,
                                                                   &pi.hProcess,
                                                                   FALSE,
                                                                   INFINITE,
                                                                   QS_ALLINPUT
                                                               )
           )
           {
               while   (   PeekMessage (   &msg,   NULL,   0,  0,  PM_REMOVE))
                       {
                           DispatchMessage     (   &msg);
                       }
           }

   GetExitCodeProcess  (   pi.hProcess,    &dwCode);

   CloseHandle (   pi.hProcess);
   CloseHandle (   pi.hThread);

   return  (   dwCode);
}
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question