Creating directory with full access permissions in Vista using VC++
-
I want to create a directory giving full access permissions to every user ( Admin and Non Admin). Can I have a sample code . Thanks...
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Thanks... I tried this.. It works in win2003 ,but not in Vista.. I need same functionality in Vista.
Didn't work on Vista? I tried the first code at that link (on Vista):
SECURITY_ATTRIBUTES sa;
SECURITY_DESCRIPTOR sd;::InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);
::SetSecurityDescriptorDacl(&sd,TRUE,NULL,FALSE);
::SetSecurityDescriptorGroup(&sd,NULL, FALSE );
::SetSecurityDescriptorSacl(&sd, FALSE, NULL, FALSE );sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = &sd;
sa.bInheritHandle = TRUE;::CreateDirectory( _T("e:\\testcreatedirectory"), &sa);
That worked fine, but the directory can be taken over by anyone. This article (Creating a DACL[^]) has sample code that works on Vista as well:
SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.bInheritHandle = FALSE;TCHAR * szSD = TEXT("D:") // Discretionary ACL
TEXT("(D;OICI;GA;;;BG)") // Deny access to built-in guests
TEXT("(D;OICI;GA;;;AN)") // Deny access to anonymous logon
//TEXT("(A;OICI;GRGWGX;;;AU)") // Allow read/write/execute to authenticated users
//TEXT("(A;OICI;GA;;;BA)"); // Allow full control to administrators
TEXT("(A;OICI;GA;;;AU)"); // Allow full control to authenticated usersif (::ConvertStringSecurityDescriptorToSecurityDescriptor(szSD,
SDDL_REVISION_1,
&sa.lpSecurityDescriptor,
NULL))
{
::CreateDirectory( _T("e:\\testcreatedirectory"), &sa);
::LocalFree(sa.lpSecurityDescriptor)
}Mark Salsbery Microsoft MVP - Visual C++ :java:
modified on Wednesday, September 17, 2008 4:19 PM
-
Thanks... I tried this.. It works in win2003 ,but not in Vista.. I need same functionality in Vista.
It seems Mark's code must be work on the vista. :)