# How can one run the app with specific environment variables?

**URL:** <https://clarionhub.com/t/how-can-one-run-the-app-with-specific-environment-variables/8332>\
**Category:** questions\
**Tags:** dotnet\
**Created:** [June 25, 2025, 8:40am UTC](https://clarionhub.com/t/how-can-one-run-the-app-with-specific-environment-variables/8332 "2025-06-25T08:40:08Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ThaDaSoft](https://clarionhub.com/user_avatar/clarionhub.com/thadasoft/32/3743_2.png) [@ThaDaSoft](https://clarionhub.com/u/ThaDaSoft)\
**Post date:** [June 25, 2025, 8:40am UTC](https://clarionhub.com/t/how-can-one-run-the-app-with-specific-environment-variables/8332/1 "2025-06-25T08:40:08Z")

</div>

In one of my projects I am calling into a DotNet DLL - which uses `System.Net.Http` - which allows setting a HTTP PROXY using an env called `https_proxy` - how can I set this ENV for my Clarion APP so my DLL get's it too?

I tried creating an `{APP_NAME}.env` file according to [env\_file.htm [Clarion Community Help]](https://clarion.help/doku.php?id=env_file.htm) but it doesn't seem to do anything

---

<div class="post-metadata">

**Author:** ![Lindersoft](https://clarionhub.com/user_avatar/clarionhub.com/lindersoft/32/5613_2.png) [@Lindersoft](https://clarionhub.com/u/Lindersoft)\
**Post date:** [June 25, 2025, 12:35pm UTC](https://clarionhub.com/t/how-can-one-run-the-app-with-specific-environment-variables/8332/2 "2025-06-25T12:35:14Z")

</div>

Try the SetEnvironmentVariable Windows API to set environment variables for the current process.

Friedrich

---

<div class="post-metadata">

**Author:** ![ThaDaSoft](https://clarionhub.com/user_avatar/clarionhub.com/thadasoft/32/3743_2.png) [@ThaDaSoft](https://clarionhub.com/u/ThaDaSoft)\
**Post date:** [June 26, 2025, 6:56am UTC](https://clarionhub.com/t/how-can-one-run-the-app-with-specific-environment-variables/8332/3 "2025-06-26T06:56:38Z")

</div>

How does one do that inside the Clarion Editor?

---

<div class="post-metadata">

**Author:** ![ArnorBld](https://clarionhub.com/letter_avatar_proxy/v4/letter/a/dfb087/32.png) [@ArnorBld](https://clarionhub.com/u/ArnorBld)\
**Post date:** [July 2, 2025, 12:11am UTC](https://clarionhub.com/t/how-can-one-run-the-app-with-specific-environment-variables/8332/4 "2025-07-02T00:11:05Z")

</div>

Hi,  
In your global map, you need:

```clarion
  MODULE('WIN32.LIB')
     mySetEnvironmentVariable( |
                   *CString lpName, |
                   *CString lpValue), |
                   LONG, RAW, PASCAL, NAME('SetEnvironmentVariableA')
  END

```

Then you can add a function or method like this:

```clarion
SetEnvVar PROCEDURE (STRING pEnvVar, STRING pValue)!!,UNSIGNED
!! See: https://learn.microsoft.com/en-us/windows/win32/api/processenv/nf-processenv-setenvironmentvariablea?redirectedfrom=MSDN
En CSTRING(SIZE(CLIP(pEnvVar))+1)
Rn CSTRING(SIZE(CLIP(pValue))+1)
  CODE
  En = CLIP(pEnvVar)
  Rn = CLIP(pValue)
  RETURN(mySetEnvironmentVariable(En,Rn))

```

That should do it 🙂

---

<div class="post-metadata">

**Author:** ![ThaDaSoft](https://clarionhub.com/user_avatar/clarionhub.com/thadasoft/32/3743_2.png) [@ThaDaSoft](https://clarionhub.com/u/ThaDaSoft)\
**Post date:** [July 2, 2025, 6:51am UTC](https://clarionhub.com/t/how-can-one-run-the-app-with-specific-environment-variables/8332/5 "2025-07-02T06:51:48Z")

</div>

i did it like below instead - but was hoping for a way to do it without adding code to the project - just by setting them in the Clarion Editor which will pass it through to the project while running - I thought that was what the `.env` file could do - but sadly it cannot

```clarion
SetEnvironmentVariable PROCEDURE(STRING lpName, <STRING lpValue>)!,BOOL
envName &CSTRING
envValue &CSTRING
result BOOL
    CODE
        envName &= NEW CSTRING(LEN(CLIP(lpName)) + 1);
        envName = lpName;
        
        IF OMITTED(lpValue)
            result = _SetEnvironmentVariableA(envName);
        ELSE
            envValue &= NEW CSTRING(LEN(CLIP(lpValue)) + 1);
            envValue = lpValue;
            result = _SetEnvironmentVariableA(envName, envValue);
        END
        
        DISPOSE(envName);
        IF NOT envValue &= NULL
            DISPOSE(envName);
        END
        
        RETURN result;

```

---

<div class="post-metadata">

**Author:** ![jslarve](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@jslarve](https://clarionhub.com/u/jslarve)\
**Post date:** [July 2, 2025, 10:18am UTC](https://clarionhub.com/t/how-can-one-run-the-app-with-specific-environment-variables/8332/6 "2025-07-02T10:18:35Z")

</div>

Without going into whether the code does what you want, you might want to revisit your DISPOSE() calls.

---

<div class="post-metadata">

**Author:** ![ThaDaSoft](https://clarionhub.com/user_avatar/clarionhub.com/thadasoft/32/3743_2.png) [@ThaDaSoft](https://clarionhub.com/u/ThaDaSoft)\
**Post date:** [July 2, 2025, 11:21am UTC](https://clarionhub.com/t/how-can-one-run-the-app-with-specific-environment-variables/8332/7 "2025-07-02T11:21:44Z")

</div>

Thanks - missed that one 🤣

---

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [July 2, 2025, 9:03pm UTC](https://clarionhub.com/t/how-can-one-run-the-app-with-specific-environment-variables/8332/8 "2025-07-02T21:03:26Z")

</div>

You can avoid the New/Dispose like this:

```clarion
SetEnvironmentVariable PROCEDURE(STRING lpName, <STRING lpValue>)!,BOOL
envName CSTRING(size(lpName)+1)
envValue CSTRING(size(lpValue)+2)
result BOOL
    CODE
        envName = Clip(lpName)  
        IF OMITTED(lpValue)
            result = _SetEnvironmentVariableA(envName);
        ELSE
            envValue = Clip(lpValue)
            result = _SetEnvironmentVariableA(envName, envValue);
        END
        RETURN CHOOSE(result)

```

The API said if it worked the result is Non-Zero. You declared to return BOOL so I return CHOOSE(result).
