Skip to content

Use GetTempPath2 on Windows if available - #104642

Merged
tommcdon merged 1 commit into
dotnet:mainfrom
tommcdon:dev/tommcdon/useGetTempPath2
Jul 10, 2024
Merged

Use GetTempPath2 on Windows if available#104642
tommcdon merged 1 commit into
dotnet:mainfrom
tommcdon:dev/tommcdon/useGetTempPath2

Conversation

@tommcdon

@tommcdon tommcdon commented Jul 9, 2024

Copy link
Copy Markdown
Member

Since Windows 10 Build 20348, there is a new API to get the temporary files path called GetTempPath2. This API returns a directory inaccessible to non-SYSTEM processes if the calling process runs as SYSTEM, and it is recommended to call this function instead of GetTempPath.

This PR tries to find GetTempPath2A / GetTempPath2W and uses that, otherwise it falls back to GetTempPathA / GetTempPathW.

Note: this PR removes an unused function GetTempPathWrapper that which referenced GetTempPathW

Since Windows 10 Build 20348, there is a new API to get the temporary files path called [`GetTempPath2`](https://learn.microsoft.com/windows/win32/api/fileapi/nf-fileapi-gettemppath2w). This API returns a directory inaccessible to non-SYSTEM processes if the calling process runs as SYSTEM, and [it is recommended to call this function instead of `GetTempPath`](https://learn.microsoft.com/windows/win32/api/fileapi/nf-fileapi-gettemppathw#remarks).

This PR tries to find `GetTempPath2A` / `GetTempPath2W` and uses that, otherwise it falls back to `GetTempPathA` / `GetTempPathW`.

*Note:* this PR removes an unused function `GetTempPathWrapper` that which referenced `GetTempPathW`
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @tommcdon
See info in area-owners.md if you want to be subscribed.

@tommcdon

Copy link
Copy Markdown
Member Author

All failures are known, merging

@tommcdon
tommcdon merged commit e3d2dd1 into dotnet:main Jul 10, 2024
matouskozak added a commit to matouskozak/runtime that referenced this pull request Jul 11, 2024
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

2 participants