आज का प्रश्न और उत्तर सत्र हमारे पास सुपरयूसर की सौजन्य है - स्टैक एक्सचेंज का एक उपविभाग, क्यू एंड ए वेब साइट्स का एक समुदाय संचालित समूह।
नोटपैड स्क्रीनशॉट डेन (सुपर यूज़र) की सौजन्य।
प्रश्न
SuperUser रीडर बॉबोज़ जानना चाहते हैं कि Windows 7 में एक अंतर्निहित विधि है और फ़ाइल को लॉक करने के लिए नए संस्करण हैं और इसे ओवरराइट या हटाए जाने से रोकते हैं:
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.
क्या विंडोज 7 और नए संस्करणों में ऐसा करने के लिए एक अंतर्निहित विधि है?
उत्तर
सुपरयूसर योगदानकर्ता दान और ब्रेकथ्रू का हमारे लिए जवाब है। सबसे पहले, दान:
I think PowerShell is probably the neatest way to accomplish this. Something like the following:
ब्रेकथ्रू से उत्तर का पालन किया:
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.
स्पष्टीकरण में जोड़ने के लिए कुछ है? टिप्पणियों में विचार व्यक्त करो। अन्य तकनीक-समझदार स्टैक एक्सचेंज उपयोगकर्ताओं से अधिक उत्तरों पढ़ना चाहते हैं? यहां पूर्ण चर्चा धागा देखें।