locked
Environment variables in a store app

    Question

  • Hi

      I´ve been trying to write my first Windows store app but can´t find any documentation on how I would go about printing the current OS Environment variables and their values within a text field.  As far as I understand it using regular c# I access the information using System.Enviroment.getEnvironmentVariables() 

    http://msdn.microsoft.com/en-us/library/1h5xxewc(v=vs.110).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-2

      but when I try to compile the hello World tutorial app on the msdn website replacing the greetings.outputText with the environment contents I get an error saying System.Environment does not contain a definition for getEnvironmentVariables.

    http://msdn.microsoft.com/en-us/library/windows/apps/hh986965.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-8

      I found one more post stating the feature is not actually implemented and a series of helper functions can be used instead, but unfortunately those don't provide a way to check the whole environment for stray or new variables.

    http://social.msdn.microsoft.com/Forums/windowsapps/en-US/87cbf2c0-32fd-471b-b5b3-fd4f13802b2d/environment-variables-query?forum=winappswithnativecode

      Now, if the above is correct then I guess the only way to access the environment on my running Windows 8 is to retrieve the keys from the local registry.  Does anyone have tips on how to iterate over registry environment variables using visual c# or an otherwise simpler way to display on screen the current environment context of a running app?

    Monday, September 01, 2014 9:19 PM

Answers

  • Hi Ævar Guðmundsson,

    The API you found not work with Windows Store App, as you can see from the version information:

    .NET Framework

    Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

    .NET Framework Client Profile

    Supported in: 4, 3.5 SP1

    If the API is workable for Windows Store App we should be able to see something different, for instance Exception Class:

    .NET Framework

    Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

    .NET Framework Client Profile

    Supported in: 4, 3.5 SP1

    Portable Class Library

    Supported in: Portable Class Library

    .NET for Windows Store apps

    Supported in: Windows 8

    .NET for Windows Phone apps

    Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

    As we know that Windows Store App runs in a sandbox mode, we cannot get the system information unless system provide us API, but unfortunately the answer is no.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, September 02, 2014 5:18 AM
    Moderator

All replies

  • Hi Ævar Guðmundsson,

    The API you found not work with Windows Store App, as you can see from the version information:

    .NET Framework

    Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

    .NET Framework Client Profile

    Supported in: 4, 3.5 SP1

    If the API is workable for Windows Store App we should be able to see something different, for instance Exception Class:

    .NET Framework

    Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

    .NET Framework Client Profile

    Supported in: 4, 3.5 SP1

    Portable Class Library

    Supported in: Portable Class Library

    .NET for Windows Store apps

    Supported in: Windows 8

    .NET for Windows Phone apps

    Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

    As we know that Windows Store App runs in a sandbox mode, we cannot get the system information unless system provide us API, but unfortunately the answer is no.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, September 02, 2014 5:18 AM
    Moderator
  • I'm in the exact same boat. This might help: http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.applicationdata.aspx

    There are APIs here that will get you to certain system folders if you're looking for say something like %localappdata% like I was.

    Tuesday, December 30, 2014 10:47 AM