大佬教程收集整理的这篇文章主要介绍了在Windows中更改文件所有者,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
// #includes omitted for the sake of sanity HANDLE token; char *filename = "somefile.txt"; char *newuser = "someuser"; DWORD len; PSecurity_DESCRIPTOR security = NULL; PSID sidPtr = NULL; int retValue = 1; // Get the privileges you need if (OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES,&token)) { SetPrivilege(token,"SeTakeownershipPrivilege",1); SetPrivilege(token,"SeSecurityPrivilege","SeBACkupPrivilege","SeRestorePrivilege",1); } else retValue = 0; // Create the security descriptor if (retvalue) { GetFileSecurity(filename,owneR_Security_INFORMATION,security,&len); security = (PSecurity_DESCRIPTOR)malloc(len); if (!InitializeSecurityDescriptor(security,Security_DESCRIPTOR_REVISION)) retValue = 0; } // Get the sid for the username if (retvalue) { char domainbuf[4096]; DWORD sidSize = 0; DWORD bufSize = 4096; SID_NAME_USE sidUse; LookupAccountName(NULL,newuser,sidPtr,&sidSize,domainbuf,&bufSize,&sidUsE); sid = (PSID)malloc(sidSizE); if (!LookupAccountName(NULL,String,(PSID)sid,&sidUsE)) retValue = 0; } } // Set the sid to be the new owner if (retValue && !SetSecurityDescriptorowner(security,0)) retValue = 0; // Save the security descriptor if (retvalue) retValue = SetFileSecurity(filename,security); if (security) free(security); if (sid) free(sid); return retValue;
`
以上是大佬教程为你收集整理的在Windows中更改文件所有者全部内容,希望文章能够帮你解决在Windows中更改文件所有者所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。