Miten lukitset tiedoston Windowsissa estääksesi poiston tai päällekirjoittamisen?

Sisällysluettelo:

Miten lukitset tiedoston Windowsissa estääksesi poiston tai päällekirjoittamisen?
Miten lukitset tiedoston Windowsissa estääksesi poiston tai päällekirjoittamisen?

Video: Miten lukitset tiedoston Windowsissa estääksesi poiston tai päällekirjoittamisen?

Video: Miten lukitset tiedoston Windowsissa estääksesi poiston tai päällekirjoittamisen?
Video: 30 Ultimate Windows 10 Tips and Tricks for 2020 - YouTube 2024, Saattaa
Anonim
Vaikka tehtävän suorittamiseen on paljon kolmannen osapuolen ohjelmia, joskus haluat vain käyttää sisäänrakennettua tapaa tehdä sama asia. Tämän päivän SuperUser Q & A -viesti auttaa lukijaa löytämään mahtavaa sisäänrakennettua ratkaisua, jotta hänen tiedostojaan ei voi poistaa tai korvata.
Vaikka tehtävän suorittamiseen on paljon kolmannen osapuolen ohjelmia, joskus haluat vain käyttää sisäänrakennettua tapaa tehdä sama asia. Tämän päivän SuperUser Q & A -viesti auttaa lukijaa löytämään mahtavaa sisäänrakennettua ratkaisua, jotta hänen tiedostojaan ei voi poistaa tai korvata.

Tämän päivän kysymys- ja vastausistunto tulee meihin SuperUserin hyväksi - Stack Exchangein alaosasto, joka on yhteisöllinen Q & A-sivustojen ryhmittely.

Notepadin kuvakaappaus Dan (SuperUser): n hyväksi.

Kysymys

SuperUser-lukija boboes haluaa tietää, onko Windows 7: ssä ja uudemmissa versioissa sisäänrakennettua menetelmää lukitsemaan tiedosto ja pitämään se ylittämättömänä tai poistettuna:

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.

Onko käytössä sisäänrakennettu menetelmä Windows 7: ssa ja uudemmissa versioissa?

Vastaus

SuperUser-avustajat Dan ja Breakthrough ovat meille vastaus. Ensin, 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

Seuraaja vastaus läpimurto:

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.

Onko jokin asia lisättävä selitykseen? Kuulkaa kommentit. Haluatko lukea lisää vastauksia muilta tech-tajuilta Stack Exchange-käyttäjiltä? Katso koko keskusteluketju täältä.

Suositeltava: