Is it possible to redirect the Windows API 'tmpfile' function?

We work with a 3rd-party tool for a software build that makes use of the tmpfile function. As security has tightened and the ability for us to run tools as an administrator is removed, we're wondering if there is a workaround for running a tool like this without administrator rights. We've considered elevated accounts for running specific builds, but this is the only tool that really needs it. Is it possible to hook the tmpfile function using an alternate DLL or some other method? We have no control over the source code of this tool, nor are we able to use a different tool at this time.


Unless the tool has its own temporary folder that it insists upon, the temporary folder's location is passed in the environment variables of the program.

These are the Windows TEMP/TMP Environment Variables. TEMP is more for Windows internal programs and TMP is for user programs. If in doubt, set both to the same value. Logout/login is required for this to take effect.

For more details see the article
Where Does Windows Store Temporary Files and How to Change TEMP Folder Location?


Specifically for the tmpfile function, Microsoft apparently didn't update it after the writing in C:\ has become restricted to programs running with Administrator permissions.

I would therefore advise running your program in a disk other than C:. If your computer doesn't have a second disk, you may reduce an existing partition, create a new one and call it D:. If you don't have the permissions for that, use a partition editor that is run from a boot media, if you have physical access to the computer. You may also run it from some external disk.

Any other solution would entail the replacement of the tmpfile function by hooking this API, if this function is used from a Windows DLL and is not statically linked into the program. This requires good Windows programming knowledge.