如何在windows中锁定文件以阻止删除或覆盖?

虽然有很多第三方程序可以完成一项任务,但有时您只想使用内置方法来完成同样的任务。今天的超级用户Q&A帖子帮助读者找到一个很棒的内置解决方案,防止他的文件被删除或覆盖。...

如何在windows中锁定文件以阻止删除或覆盖?

虽然有很多第三方程序可以完成一项任务,但有时您只想使用内置方法来完成同样的任务。今天的超级用户Q&A帖子帮助读者找到一个很棒的内置解决方案,防止他的文件被删除或覆盖。

今天的问答环节是由SuperUser提供的,SuperUser是Stack Exchange的一个分支,是一个由社区驱动的问答网站分组。

记事本截图由丹(超级用户)提供。

问题

超级用户读者boboes想知道在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 editi***?

I know that there are programs for doing this. My question is if there is a built in mechani** in Windows 7 and newer editi***. 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 suggesti*** here: How to purposefully exclusively lock a file? Unfortunately, they require 3rd party tools or changing the file to a locked state.

在Windows7和更新版本中是否有内置的方法来执行此操作?

答案

超级用户贡献者丹和突破为我们提供了答案。首先,丹:

I think PowerShell is probably the neatest way to accomplish this. Something like the following:

007Ys3FFgy1gpf6kvjxiuj30hd06qmxl

While paused, the above script causes the following prompt when attempting to open up “myfile.txt”:

007Ys3FFgy1gpf6kw64j9j30hd04q0sq

接着是突破的答案:

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, provisi*** exist to lock the file for read/write only, or a combination thereof.


有什么要补充的解释吗?在评论中发出声音。想从其他精通技术的Stack Exchange用户那里了解更多答案吗?在这里查看完整的讨论主题。

  • 发表于 2021-04-11 01:52
  • 阅读 ( 167 )
  • 分类:互联网

你可能感兴趣的文章

7小众windows桌面实用程序你一定要试试

...2018年。你今年有什么新年决心?希望其中之一是在你的Windows操作系统上尝试一些新的应用程序。如果你真的下了决心,你就来对地方了。 ...

  • 发布于 2021-03-13 21:53
  • 阅读 ( 234 )

完整的恶意软件删除指南

...个逐步删除大量恶意软件的方法。此外,我们将向您展示如何阻止恶意软件感染您的系统,首先。如果你不必担心恶意软件,你将有更多的时间在生活中更好的事情。 ...

  • 发布于 2021-03-14 00:00
  • 阅读 ( 246 )

7个你永远无法理解的windows谜团

...视为一个名为Windows的文件夹中的文件。你可以想象这将如何引起混乱,所以计算机根本不允许。 ...

  • 发布于 2021-03-14 02:33
  • 阅读 ( 231 )

如何删除其他程序正在使用的文件

... 如何克服“文件在用”错误 ...

  • 发布于 2021-03-18 06:15
  • 阅读 ( 199 )

如何阻止internet explorer访问internet

... 尽管如此,您可能仍然想知道如何禁用Internet Explorer(IE)。也许你不想让系统中的其他用户在笨重的浏览器中工作,或者只是讨厌它并想从你的系统中阻止Internet Explorer。 ...

  • 发布于 2021-03-19 06:29
  • 阅读 ( 224 )

如何在linux下访问和使用windowscdrive

你在你的电脑上运行Linux,但你也安装了Windows。这是一个双引导,但有时您希望在两个操作系统之间共享数据。 ...

  • 发布于 2021-03-26 10:17
  • 阅读 ( 202 )

如何使用windows defender防范勒索软件

...其中之一是Windows10上的WindowsDefender内置的新功能。下面是如何使用它。 ...

  • 发布于 2021-03-26 10:27
  • 阅读 ( 235 )

如何阻止chrome上的网站

... 如果你想在你的**上也这样做,看看如何阻止Android上的网站。 ...

  • 发布于 2021-03-26 13:28
  • 阅读 ( 199 )

什么是lokibot恶意软件?你如何保护自己?

...要知道的关于这种威胁,你可以做什么来保护自己,以及如何处理洛基博特感染。 ...

  • 发布于 2021-03-29 03:47
  • 阅读 ( 287 )

如何删除windows pc上的病毒和恶意软件

...描您的电脑上的恶意软件,并删除任何您发现的。以下是如何清除你的电脑病毒和恶意软件。 虽然许多病毒和其他类型的恶意软件的设计只是为了引起混乱,但越来越多的恶意软件是由有组织犯罪**的,目的是窃取信用卡号码、...

  • 发布于 2021-04-06 08:41
  • 阅读 ( 276 )
lftt3317
lftt3317

0 篇文章

相关推荐