Does Environment.SetEnvironmentVariable work in UWP?

MG Bhadurudeen 626 Reputation points
2021-01-07T15:47:05.64+00:00

Hello, does Environment.SetEnvironmentVariable work in UWP? You might ask me to test it myself, I have tested it, but no results.
It neither throws any exception nor does anything. Is there any mistake with me?

Regards.

Universal Windows Platform (UWP)
{count} votes

Accepted answer
  1. Roy Li - MSFT 33,366 Reputation points Microsoft Vendor
    2021-01-14T07:06:43.313+00:00

    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.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.