I have a requirement to change the ownership of a file or revoke the ownership of the user who created the file using Powerbuilder. i.e. in my application user creates a file and I want to remove his ownership from the file immediately within code. So that user can't edit or modify the file. I have found some c++ samples for the same (Change file owner in Windows) but could not replicate it in Powerbuilder. Getting error code 87 with below code when calling SetNamedSecurityInfoW. If anyone can help me to achieve Ownership change using Powerbuilder.
CONSTANT Integer SE_FILE_OBJECT = 1
CONSTANT Integer OWNER_SECURITY_INFORMATION = 1
CONSTANT Integer NAME_SIZE = 64
CONSTANT Integer SID_SIZE = 32
String domain_name
Integer ret, sid_len, domain_len
integer li_ret, newowner
n_filesys nvo
Integer l_nothing
SetNull(l_nothing)
newowner = 100
li_ret = nvo.SetNamedSecurityInfoW('P:\My Documents\Test.txt',SE_FILE_OBJECT,OWNER_SECURITY_INFORMATION,newowner,l_nothing,l_nothing,l_nothing)
If li_ret <> 0 Then
messagebox("Hi","Error")
end if
---------------------------------------------------------------------
Declaration of SetNamedSecurityInfoW:---
Function Integer SetNamedSecurityInfo ( &
String ObjectName, &
Integer ObjectType, &
Integer SecurityInfo, &
Long sidOwner, &
Long sidGroup, &
Long Dacl, &
Long Sacl &
) Library "advapi32.dll"