Hvordan låser du en fil i Windows for å blokkere sletting eller overskrivning?

Innholdsfortegnelse:

Hvordan låser du en fil i Windows for å blokkere sletting eller overskrivning?
Hvordan låser du en fil i Windows for å blokkere sletting eller overskrivning?

Video: Hvordan låser du en fil i Windows for å blokkere sletting eller overskrivning?

Video: Hvordan låser du en fil i Windows for å blokkere sletting eller overskrivning?
Video: Solved: Setup was unable to create a new system partition or locate an existing system partition - YouTube 2024, April
Anonim
Mens det er mange tredjepartsprogrammer for å utføre en oppgave, vil du noen ganger bare bruke en innebygd metode for å gjøre det samme. Dagens SuperUser Q & A-innlegg hjelper en leser til å finne en fantastisk innebygd løsning for å hindre at filene blir slettet eller overskrevet.
Mens det er mange tredjepartsprogrammer for å utføre en oppgave, vil du noen ganger bare bruke en innebygd metode for å gjøre det samme. Dagens SuperUser Q & A-innlegg hjelper en leser til å finne en fantastisk innebygd løsning for å hindre at filene blir slettet eller overskrevet.

Dagens Spørsmål & Svar-sesjon kommer til oss med høflighet av SuperUser-en underavdeling av Stack Exchange, en fellesskapsdrevet gruppering av Q & A-nettsteder.

Notisblokk skjermbilde høflighet av Dan (SuperUser).

Spørsmålet

SuperUser leser boboes vil vite om det er en innebygd metode i Windows 7 og nyere utgaver for å låse en fil og holde den fra å bli overskrevet eller slettet:

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.

Er det en innebygd metode for å gjøre dette i Windows 7 og nyere utgaver?

Svaret

SuperUser-bidragsytere Dan og gjennombrudd har svaret for oss. Først opp, 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

Etterfulgt av svaret fra gjennombrudd:

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.

Har du noe å legge til forklaringen? Lyder av i kommentarene. Vil du lese flere svar fra andre tech-savvy Stack Exchange-brukere? Sjekk ut hele diskusjonstråden her.

Anbefalt: