Question: Just looking for some advice on doing CodeDeploy on Windows. I've used it for a year on Linux boxes, this is my first Windows Server on EC2 and I can't seem to get past "Permission Denied" errors.

I've changed the permissions in Windows on the folders, but the Deploy is failing on the Install step on CodeDeploy.

```
Error CodeUnknownError
Script Name
MessagePermission denied - c:/inetpub/render
Log Tail

```

appspec.yml

```
version: 0.0
os: windows
files:
 - source: /
   destination: /inetpub/render
hooks:
  AfterInstall:
    - location: aws/scripts/deploy.bat
      runas: administrator
      timeout: 1200

```

I've tried both Windows and Linux style pathing (C:\inetpub\render) because examples aren't clear, but nothing has worked.

Answer: 
In my case the "Permission denied @ unlink\_internal" was caused by dotnet.exe process locking one of the dll's. You can find out what locks your file using Microsoft [Process Explorer](https://learn.microsoft.com/en-us/sysinternals/downloads/process-explorer). You can then update your appspec.yml BeforeInstall hook to kill the process before files are updated:

```
version: 0.0
os: windows
files:
  - source: \files
    destination: C:\inetpub\wwwroot\yoursite
hooks:
  BeforeInstall:
    - location: stopsite.bat
      timeout: 300
      runas: Administrator
  AfterInstall:
    - location: startsite.bat
      timeout: 300
      runas: Administrator

```

Where stopsite.bat contains the following commands:

```
C:\Windows\System32\inetsrv\appcmd stop site "yoursite"
taskkill /IM "dotnet.exe" /F

```
The error "Permision Denied" on a Windows Instance while using CodeDeploy is usually because one or more files that you are trying to depoloy is already in use. (May be a .exe already running, A file open in notepad etc.).

Please see if this is the case and if so either manually stop the process that are using these files or you can use the ApplicationStop,BeforeInstall hooks to configure scripts that will stop any running process before going in for Install.