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:
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ä.