Kako zaključati datoteku u sustavu Windows za blokiranje brisanja ili prebrisivanja?

Sadržaj:

Kako zaključati datoteku u sustavu Windows za blokiranje brisanja ili prebrisivanja?
Kako zaključati datoteku u sustavu Windows za blokiranje brisanja ili prebrisivanja?
Anonim
Iako postoje brojni programi trećih strana za obavljanje zadataka, ponekad samo želite upotrijebiti ugrađenu metodu za istu stvar. Danas SuperUser Q & A pomaže čitatelju pronaći strašno izgrađen-in rješenje kako bi njegove datoteke izbrisati ili prepisati.
Iako postoje brojni programi trećih strana za obavljanje zadataka, ponekad samo želite upotrijebiti ugrađenu metodu za istu stvar. Danas SuperUser Q & A pomaže čitatelju pronaći strašno izgrađen-in rješenje kako bi njegove datoteke izbrisati ili prepisati.

Današnja pitanja i odgovori nam se javljaju zahvaljujući SuperUseru - podjele Stack Exchange-a, zajednice-driven grupiranja Q & A web stranica.

Snimak zaslona Notepada zahvaljujući Danu (SuperUser).

Pitanje

Superobraktor čitač boboes želi znati ima li izgrađen-in metoda u sustavu Windows 7 i novijih izdanja za zaključavanje datoteke i zadržati da se prebrisati ili izbrisati:

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.

Postoji li izgrađena metoda za to u sustavu Windows 7 i novijim izdanjima?

Odgovor

Dan i Probijanje korisnicima SuperUser-a imaju odgovor za nas. Prvo, Dan:

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

Slijedi odgovor tvrtke Breakthrough:

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.

Imate li nešto za objašnjenje? Zvuči u komentarima. Želite li pročitati više odgovora od drugih tehnoloških korisnika Stack Exchangea? Pogledajte ovdje cijelu raspravu.

Preporučeni: