0

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"
Community
  • 1
  • 1
  • I suspect if the user has the privilege necessary to change the ownership away, he has the privilege to change it back. – Hugh Brackett Jul 05 '12 at 19:42

1 Answers1

1

According to the list of Windows system error codes, you have an invalid parameter. My guess would be the sidOwner, sidGroup, Dacl, and Sacl parameters. These are all pointers to structures, so it would probably be best to actually define the structures and pass them in by reference. Passing in an integer for sidOwner is definitely going to cause a problem. Declaring the structure doesn't look very straight-forward, either, but you can get started using the documentation here.

Jason 'Bug' Fenter
  • 1,616
  • 1
  • 16
  • 27