Are locked files blocking your deployments? Have you tried shutting down a website in a PowerShell step, to still get the locked files error? Well, you aren't the only one.
This is a very common support request that we receive. Error messages such as:
Unable to copy the package to the specified directory 'c:\MyDeploymentLocation'. One or more files in the directory may be locked by another process.
Can be frustrating, and trying to find the source of the lock by stopping processes you think might be accessing the file is a bit of a guessing game.
Well guess no more! Handle is a utility from SysInternals, written to show you all of the programs that have a file open (and thus locked!)
If you look at your specific error and find the file name:
The process cannot access the file 'c:\MyDeploymentLocation\Web.config'
You can then use Handle to find what has that file open such as:
C:\Handle> handle C:\MyDeploymentLocation Handle v3.51 Copyright (C) 1997-2013 Mark Russinovich Sysinternals - www.sysinternals.com explorer.exe pid: 3732 type: File C7C: C:\MyDeploymentLocation\Web.config
This will allow you to use a PowerShell script step to first stop these process, allowing you to complete your deployment without locked files getting in the way!
When Handle.exe runs for the first time, you'll be prompted to accept an End User License Agreement. Accepting the agreement is stored in the registry, per-user. If you're running Handle.exe from the Octopus Deploy Tentacle agent and it is hanging, it's likely to be because Tentacle is running under a user account that hasn't accepted the license agreement. You can accept the license agreement automatically by running the following command before calling Handle.exe:
& reg.exe ADD "HKCU\Software\Sysinternals\Handle" /v EulaAccepted /t REG_DWORD /d 1 /f
Octopus Deploy is used by thousands of developers across the globe, from small companies to large enterprises. Find out if it meets your deployment automation needs by taking advantage of our free 30-day trial. You can spin up an instance with just a few clicks!