System folders are protected

You may or may not aware that windows 11 has a protection that is called Randsom ware protection (Windows 10 has a similar protection but not the same).
This blocks programs to write (and sometimes read) files on certain default folders (and more if the user has added custom folders too).

If you try to access those folders when this protection is enabled, you will get a NilObjectException crash (that cannot be catched). Even just linking it to a FolderItem will result in a crash.

These are the the default folders:

  • c:\Users\<username>\Documents
  • c:\Users\Public\Documents
  • c:\Users\<username>\Pictures
  • c:\Users\Public\Pictures
  • c:\Users\Public\Videos
  • c:\Users\<username>\Videos
  • c:\Users\<username>\Music
  • c:\Users\Public\Music
  • c:\Users\<username>\Favorites

So keep that in mind.
Also, atm this protection is disabled by default. But I did read Microsoft are considering this to be enabled by default.

On a side note: maybe Xojo Inc could add a way to catch the NilObjectException.

Here a link to the MS docs:

Ransomware protection. Both Win 10 and Win 11 have it.

I don’t get it. Things like these always worked:

Var nilFolder As FolderItem
Try
  MessageBox nilFolder.Exists.ToString // Nil Object Exception
Catch e As NilObjectException
  MessageBox "NOE was catched"
End

break

How to reproduce such non-catchable NOE ?

Try this with Ransomware enabled:

var f as FolderItem
f = SpecialFolder.Movies.child(“test.txt”)

try
Var t As TextOutputStream = TextOutputStream.Create(f)
t.Close
catch
end

And you get this:

But you show us an IOException, no NilObjectException?

May it be possible that the test.txt File already exist or any other issue exists?

Instead of just using catch, do you have different results if you specify the exception type ? Such as

Catch ex as RuntimeException

That’s an IOException, error 2. No folder or file found.

So FolderItem is ok, SpecialFolder is ok.

But you can’t get a write permission there. The system hides/forbid things under some circumstances.

Here I do intercept it without problems.

This does work.
But it’s odd… just ‘Catch’ should be enough to catch any exception, not?

try
catch
end

Should catch any exception. But it seems, it doesn’t do that for this specific issue. Which is a bug imo.

Here it does work. The behavior shown is:

  1. It Breaks on the line where the exception occurs. It does not fire any message box.
  2. You resume the run and it continues without any problem, so the exception was discarded.

By the way: Xojo 2022R4.1 on Windows 10+

Did you enable Ransomware protection?

Sure. When I disable it, it does not raise that catched exception.

RP disabled:

RP Enabled:

Then resumed:

1 Like

I am running an older Xojo version for Windows. Will try the latest version.

1 Like

So is there a case where trying to access user\Documents or user\Desktop or user\AppData\Roaming for example, results in an NOE? Or is it always an I/O Exception? I have an NOE issues that only affects certain users (who I think may all be on Windows 11) and am wondering if it could be related.

user\Documents cannot be written to when Ransomware protection is enabled.
See all folders that are protected by default in the original mail.

Yes, I understood that, but your original post said that it resulted in a NilObjectException, but your example screenshot showed an IOException, so I’m asking if an NOE ever does in fact occur.

To be honest, I don’t use catch without specifying.

1 Like

Interesting discussion here. The question is not if and how to react on the occurance of a protected folder. The question should be:

How can I write into that folder if it is protected?

The answer is: Not at all. (If protection stays switched on)

My solution was to create a new directory in the “User” directory. This can be used without any problems. Microsoft: :clown_face:

1 Like