Tänane küsimuste ja vastuste seanss jõuab meile viisakalt SuperUserini - Stack Exchange'i ja kogukonnapõhiste Q & A veebisaitide rühmitusse.
Notepad ekraanipildi viisakus Dan (SuperUser).
Küsimus
SuperUser lugejaboboes soovib teada, kas faili lukustamiseks on Windows 7-s ja uuemates versioonides sisseehitatud meetod ja see ei tohi üle kirjutada ega kustutada:
Is there a way to lock a file with in-house means so that it cannot be deleted or overwritten? I need to temporarily lock files while testing copy scripts in order to check the error handling in those scripts. Until Windows XP, I would load a file in debug.exe to lock it. Is there a way to do this in Windows 7 and newer editions?
I know that there are programs for doing this. My question is if there is a built in mechanism in Windows 7 and newer editions. Sometimes I have to check a script on a PC and do not want to install new programs for that.
There are also some good suggestions here: How to purposefully exclusively lock a file? Unfortunately, they require 3rd party tools or changing the file to a locked state.
Kas sellel on sisseehitatud meetod Windows 7 ja uuemates versioonides?
Vastus
SuperUseri kaasautorid Dan ja läbimurre on meile vastuseks. Esiteks üles, Dan:
I think PowerShell is probably the neatest way to accomplish this. Something like the following:
Järgneb läbimurde vastus:
For the curious, here is the MSDN link to the File::Open method detailing the parameters of the call (specifically, the last argument ‘None’, declines sharing the file with any other threads/processes). Likewise, provisions exist to lock the file for read/write only, or a combination thereof.
Kas teil on seletamiseks midagi lisada? Helistage kommentaarides. Kas soovite lugeda rohkem vastuseid teistelt tech-savvy Stack Exchange'i kasutajatelt? Tutvu täieliku arutelu teemaga siit.