Avatar of ilava
ilava

asked on 

need to backup/ restore ACL permissions

how to set the file security values(ACL permissions) to a particular file/folder ...in windows

i read it somewhere GetFileSecurity and SetFileSecurity is used for this...

but im not clear with this.

my req is i need to back up a file/folder with their ACL permissions and restore them with the same ACL permissions .
Windows OSC++Security

Avatar of undefined
Last Comment
Vee_Mod
Avatar of oBdA
oBdA

Use robocopy.exe and the /copy:datsou (or whatever attributes you want to copy). robocopy is a pretty powerful tool, check robocopy.doc in the install folder for details.
Windows Server 2003 Resource Kit Tools
http://www.microsoft.com/downloads/details.aspx?FamilyID=9D467A69-57FF-4AE7-96EE-B18C4790CFFD&displaylang=en
Avatar of Deepu Abraham
Deepu Abraham
Flag of United States of America image

This is an extract from msdn:

#include <windows.h>
#include <stdio.h>

void main()
{
   WIN32_FIND_DATA FileData;
   HANDLE hSearch;
   DWORD dwAttrs;  
   TCHAR szDirPath[] = TEXT("c:\\TextRO\\");
   TCHAR szNewPath[MAX_PATH];  
 
   BOOL fFinished = FALSE;
 
// Create a new directory.
 
   if (!CreateDirectory(szDirPath, NULL))
   {
      printf("Could not create new directory.\n");
      return;
   }
 
// Start searching for text files in the current directory.
 
   hSearch = FindFirstFile(TEXT("*.txt"), &FileData);
   if (hSearch == INVALID_HANDLE_VALUE)
   {
      printf("No text files found.\n");
      return;
   }
 
// Copy each .TXT file to the new directory
// and change it to read only, if not already.
 
   while (!fFinished)
   {
      lstrcpy(szNewPath, szDirPath);
      lstrcat(szNewPath, FileData.cFileName);
      if (CopyFile(FileData.cFileName, szNewPath, FALSE))
      {
         dwAttrs = GetFileAttributes(FileData.cFileName);
         if( GetLastError() != 0 ) return;

         if (!(dwAttrs & FILE_ATTRIBUTE_READONLY))
         {
            SetFileAttributes(szNewPath,
                dwAttrs | FILE_ATTRIBUTE_READONLY);
         }
      }
      else
      {
         printf("Could not copy file.\n");
         return;
      }
 
      if (!FindNextFile(hSearch, &FileData))
      {
         if (GetLastError() == ERROR_NO_MORE_FILES)
         {
            printf("Copied all text files.\n");
            fFinished = TRUE;
         }
         else
         {
            printf("Could not find next file.\n");
            return;
         }
      }
   }
 
// Close the search handle.
 
   FindClose(hSearch);
}
Hope it helps:
Best Regards,
DeepuAbrahamK
Avatar of ilava
ilava

ASKER


I found answer my self. I used GetFileSecurity() and SetFileSecurity() for this.

Thanks

- Prince
ASKER CERTIFIED SOLUTION
Avatar of ilava
ilava

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Vee_Mod
Vee_Mod
Flag of United States of America image

Closed, 50 points refunded.
Vee_Mod
Community Support Moderator
Windows OS
Windows OS

This topic area includes legacy versions of Windows prior to Windows 2000: Windows 3/3.1, Windows 95 and Windows 98, plus any other Windows-related versions including Windows Mobile.

129K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo