What is WinRT analogue for CreateFile dwShareMode?

In the Win32 CreateFile () API, I can specify dwShareMode when I open a file to prevent that file from being deleted or changed when I open it.

I'm looking for a C # analog in WinRT. Suppose I open a file:

StorageFile sf = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync("x.txt");
IRandomAccessStreamWithContentType iras = await sf.OpenReadAsync();

      

Then, from the CMD.EXE instance, I can write a CD to the ... \ AppData \ Local \ Packages \ zzz \ LocalState directory and delete the file while the WinRT application opens.

What can I do in my C # code to cause the error to delete?

+3


source to share


1 answer


Not available. This is typical of WinRT, it forces applications to play nicely, rather than maintaining resources at the api level, just not exposing the capabilities. This is also a rather serious usability issue, the application can be suspended for a very long time when the user disconnects from it. Saving a file that takes a long time is of course very problematic, the user does not have a good way to diagnose the problem.

This is not a problem anyway when you are using LocalFolder and no one can do it. Well, not counting someone with God's account.



A backdoor is available, you can pinvoke CreateFile2 (). The version of CreateFile () that Store apps are allowed to use. It has a dwShareMode argument. Using it in a C # program is very fun and you will have non-zero coefficients for rejecting store validation.

+1


source







All Articles