mar*_*gle 28 windows-7 filesystems lock
有没有办法使用板载工具锁定文件,使其不能被删除或覆盖?
为了测试复制脚本,我需要lock files temporarily检查脚本中的错误处理。直到 XP 我使用在 debug.exe 中加载文件来锁定它。
Windows 7(及更高版本)有办法吗?
编辑
我知道有程序这样做。我的问题是 Windows 中是否有内置机制。有时我必须检查 PC 上的脚本,不想为此安装新程序。
Edit2
这里也有很好的建议:如何有目的地独占锁定文件?,但是,这需要第 3 方工具或更改要锁定的文件。
Dan*_*Dan 52
我认为 PowerShell 可能是实现这一目标的最佳方式。类似于以下内容:
#Specify the file name
$fileName = "C:\myfile.txt"
#Open the file in read only mode, without sharing (I.e., locked as requested)
$file = [System.io.File]::Open($fileName, 'Open', 'Read', 'None')
#Wait in the above (file locked) state until the user presses a key
Write-Host "Press any key to continue ..."
$null = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
#Close the file (This releases the current handle and unlocks the file)
$file.Close()
Run Code Online (Sandbox Code Playgroud)
暂停时,上述脚本在尝试打开“myfile.txt”时会导致以下提示:

| 归档时间: |
|
| 查看次数: |
11373 次 |
| 最近记录: |