Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

can`t set an owner to file Question

$
0
0

Hello, guys.

I`m trying to set owner to file using SetFileSecurity function. 

but I can`t complete my task due to a error.

Error code is 5. (no access)

Look below the code

hFile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

if ((GetFileSecurity(filename, DACL_SECURITY_INFORMATION,psd,1000000,&sdsize)) == 0)  // no error

if ((GetSecurityDescriptorDacl(psd, &DaclPresent, &pacl, &DaclDefaulted)) == 0)  // no error

if (GetAclInformation(pacl, &AclSize, sizeof(AclSize), AclSizeInformation)) // no error

LookupAccountSid(NULL, &pace->SidStart, AccountName, &AccountLen, DomainName, &DomainLen, &snu) // no error

SetAclInformation(pacl, &AclSize, sizeof(AclSize), AclSizeInformation) // no error

InitializeSecurityDescriptor(psd, SECURITY_DESCRIPTOR_REVISION) // no error

if (SetSecurityDescriptorDacl(psd, TRUE, pacl, FALSE) == 0)  // no error

if (SetFileSecurity(filename, DACL_SECURITY_INFORMATION, psd) == 0) // it returns error 5

OS : Windows 2008

Wanna change ownership of a file : C:\Windows\System32\cmd.exe

Please, help me!!!!!

Thanks In Advance.


Viewing all articles
Browse latest Browse all 15302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>