You have to give yourself the permissions to read and write in MiKTeX 2.9 folder.
Go to Program Files and right click MiKTeX 2.9 folder. Then click Properties > Security Tab > Edit Button. Select Users (Bla/Bla) from the list and check all grants.
If that is not enough, click Advanced button on the Security Tab. A window named Advanced Security Settings for Folder Name pops up. Then click Auditing Tab > Continue Button > Add Button. Type Users under "Enter the object names to select" and click OK.
Or, simply don't put your MiKTeX 2.9 folder into Program Files.
I found another potential solution to this problem: make sure that your TMP environment variable points to a writable source. For instance, I changed my TEMP and TMP environment variables (System -> Advanced -> Env. Variables) to a drive other than C:, but I accidentally had the TMP instance point to the D: drive instead of E: -- the former was unwritable. The API Access Error 5 for the MikTeX installation/removal was resolved when I fixed the TMP path.
Apparently you need Administrator rights. What is important is how you installed miktex. If you are asked wether you want to install miktex just for the current user or for all, I reccommend selecting install for all. If you select just for me, it is installed without admin rights, even if the logged in user is in fact an Administrator.
In short: uninstall and install with option "install" for all users" fixed it for me
I got the same error during MiKTeX's installation. To solve this, I right clicked on the downloaded MiKTeX installation file, "Run as administrator", and marked the "Install for all users" box. Everything worked after that.
I experienced that this problem arrises when a new package is installed and I press 'stop' at the "play/stop" button (to generate a PDF) too soon. When I press too soon the package is not installed correctly and it will not work, giving acces denied. In my case I saved my tex code file in a .txt file and deleted the entire editing program from my program files (Texworks, MIkTex). Make sure to first shut down your computer, because all relating programs have to be closed (best achieved by just shutting down the computer). Then re-install your program again and make sure to not click the "play/stop" button too soon again when a package is installed.
It worked for me so I figured why not share it ;)!
Just wanted to mention a scenario where I got error 5 'access denied'.
I run lualatex from an ASP.NET web site under impersonation. According to this http://support.microsoft.com/en-us/kb/317012 an impersonating user actually uses Default User directory and runs as NETWORK SERVICE. I might be getting it wrong, but the solution is anyway,
to create MikTex folder under Default User\Application Data give NETWORK SERVICE Write/Modify access to that folder. Then I had to give NETWORK SERVICE write/modify access to the folder where the web page dumped the .tex files to be compiled.
Access is deniedmight be caused by that. Did you tried to reboot and try it again? Under Windows this is always good advice.
initexmf --admin --update-fndbin the console as mentioned in the link.