Kaip galite užrakinti failą "Windows", kad užblokuotų panaikinimą ar perrašymą?

Turinys:

Kaip galite užrakinti failą "Windows", kad užblokuotų panaikinimą ar perrašymą?
Kaip galite užrakinti failą "Windows", kad užblokuotų panaikinimą ar perrašymą?
Anonim
Nors yra daugybė trečiųjų programų, skirtų užduočiai įvykdyti, kartais tiesiog norite naudoti tą patį įdiegtą metodą. Šiandien "SuperUser Q &A" žinutė padeda skaitytojui rasti nuostabų integruotą sprendimą, kad jo failai nebūtų ištrinti ar perrašyti.
Nors yra daugybė trečiųjų programų, skirtų užduočiai įvykdyti, kartais tiesiog norite naudoti tą patį įdiegtą metodą. Šiandien "SuperUser Q &A" žinutė padeda skaitytojui rasti nuostabų integruotą sprendimą, kad jo failai nebūtų ištrinti ar perrašyti.

Šiandieninė klausimų ir atsakymų sesija pateikiama su "SuperUser" - "Stack Exchange", bendruomenės valdoma Q & A grupių asociacija.

Užrašų ekrano ekranas su "Dan" ("SuperUser") mandagumo.

Klausimas

"SuperUser" skaitytuvo "boboes" nori žinoti, ar "Windows 7" ir naujesnėse versijose yra įdiegtas metodas, kad užfiksuotų failą ir nebūtų perrašytas ar ištrintas:

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.

Ar yra įdiegto metodo, kaip tai padaryti "Windows 7" ir naujesnėse versijose?

Atsakymas

"SuperUser" autoriai Dan ir "Breakthrough" turi mums atsakymą. Pirmiausia, Danas:

I think PowerShell is probably the neatest way to accomplish this. Something like the following:

While paused, the above script causes the following prompt when attempting to open up “myfile.txt”:
While paused, the above script causes the following prompt when attempting to open up “myfile.txt”:
Image
Image

Vykdant "Breakthrough" atsakymą:

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.

Ar turite ką nors įtraukti į paaiškinimą? Garsas išjungtas komentaruose. Norite skaityti daugiau atsakymų iš kitų "Tech-savvy Stack Exchange" vartotojų? Patikrinkite visą diskusijų temą čia.

Rekomenduojamas: