Created
July 2, 2015 14:46
-
-
Save jimbobbennett/617d5741dcbf09a01848 to your computer and use it in GitHub Desktop.
Code to put an exclusive lock on a file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param([string]$fileName) | |
#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 | |
$file.Close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment