Šodienas jautājumu un atbilžu sesija mums priecājas par SuperUser - Stack Exchange dalību, kas ir kopienas vadīta Q & A tīmekļa vietņu grupa.
Notepad screenshot pieklājīgi no Dan (SuperUser).
Jautājums
SuperUser lasītājs boboes vēlas zināt, vai operētājsistēmā Windows 7 un jaunākos izdevumos ir iebūvēta metode, lai bloķētu failu un saglabātu tā pārrakstīšanu vai izdzēšanu:
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.
Vai ir iebūvēta metode, kā to izdarīt sistēmā Windows 7 un jaunākos izdevumos?
Atbilde
SuperUser autori Dan un Breakthrough ir atbildīgi par mums. Pirmkārt, Dan:
I think PowerShell is probably the neatest way to accomplish this. Something like the following:
Seko atbilde no izrāvienu:
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.
Vai kaut ko pievienot paskaidrojumam? Skatieties komentāros. Vēlaties lasīt citas atbildes no citiem tehnoloģiju savvy Stack Exchange lietotājiem? Šeit skatiet pilnu diskusiju pavedienu.