Hello,
Welcome to Microsoft Q&A!
does Environment.SetEnvironmentVariable work in UWP
I have to say that the behavior you are getting is expected. The Environment.SetEnvironmentVariable is able to use in UWP apps, so you can call it without errors. But UWP apps are running in the sandbox, so it has limitations when accessing to the system values. You could not set System environment variable or User environment variable in UWP apps.
If you really need it, you could try to package a console app with your UWP app and use FullTrustProcessLauncher class to launch it. Then you could call the Environment class in the console app. You could refer to @Fay 's answer here: Launch .exe app.
Thank you.
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.