Windows: open file for writing (lock file)

Sometimes you need to lock file and investigate how an application under the test will be working.

There are few steps to implement it:

  1. Open PowerShell console
  2. Write the following code:
    $file=[]::Open('full/path/to/your/file', 'append', 'Write', 'None')
  3. Your test steps…
  4. Don’t forget to close the file after testing by

P.S.: It’s possible that it’ll be the error in your application log:

Exception calling "Open" with "4" argument(s): "The process cannot access the file 'full/path/to/your/file'' because it is being used by another process."