Solved

Restrict access to a folder

Posted on 2006-06-19
6
656 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
  • 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
how do i create updater to My Activex application? 3 74
Detect CR LF to each line 12 137
post4 challenge 28 83
mapAB Challlenge 35 89
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now