1

My app needs to write (and move) files to a folder from a non-admin user, and that user has no permission to use that folder.

I tried changing the permissions for the folder but it doesn't appear to have an effect.

Are there built-in restrictions from allowing me to do that?

What I do is write to Documents and then attempt to move file to final folder, which fails...

Thanks for any answers!

Here is the code:

  Dim t as TextOutputStream
  Dim tempfile as FolderItem = SpecialFolder.Documents.Child(filePath.Name)

  t = tempfile.CreateTextFile
  t.Write fileData
  t.close

  Dim p as New Permissions( 0 )

  p.OthersExecute = True
  p.OthersWrite = True
  p.OthersRead = True

  filePath.Parent.Permissions = p

  tempfile.MoveFileTo filePath.Parent
Hanaan Rosenthal
  • 1,359
  • 1
  • 11
  • 20

2 Answers2

2

The OS is designed to STOP this sort of thing as it's a huge security hole otherwise

npalardy
  • 61
  • 1
2

You could use one of the functions in the Monkeybread Software plugin, AuthorizationMBS, to allow authorization, assuming the user can elevate the security level. In a class of mine that has to get into a System location, I have this:

Protected Function mbsAuthorize() As boolean
  dim a as AuthorizationMBS
  dim s(2) as String

  if mbsAuthorized then
    mbsForm = mbsAuth.ExternalForm
    Return true
  else
    a = New AuthorizationMBS
    If a.NewAuthorization(nil, a.kAuthorizationFlagPreAuthorize) Then
      a.SimpleAuthorize

      if a.Authorized then
        mbsAuth=a // save so the externalform doesn't get invalid
        mbsForm=a.ExternalForm // copy to string for later use.
        Return true
      end if
    else
      break
    End if
  end

  return false
End Function

The class has these properties:

mbsForm as string

mbsAuth as AuthorizationMBS

BKeeney Software
  • 1,299
  • 6
  • 8