Welcome to the SRP Forum! Please refer to the SRP Forum FAQ post if you have any questions regarding how the forum works.

is there a way to read windows environment variables?

I think I should know this but I am drawing a blank. Thanks.

Comments

  • Depending on how new your OI is, the GetEnvironmentVariable function should be defined.
  • Hi Don.
    I see that in the DLL_Kernel32, but it doesn't appear in the OI documentation. Am I missing it there?
    Thanks.
  • I don't think the Win API functions are documented. I can't remember the exact calling syntax, but I imagine you just need to pass in the variable name, perhaps appended with Char(0).
  • Actually, try this:

    mybuffer=STR(char(0),4096) result = GetEnvironmentVariable(Variable:char(0),mybuffer,4096) return mybuffer[1,result]
  • Don,
    I just tried this, but am seeing null as the result. I ran this command in a dos window in my OI app directory:

    set uploads=C:\Temp

    Then added this code to my OI program:

    mybuffer = STR(char(0),4096)
    result = GetEnvironmentVariable('uploads':char(0),mybuffer,4096)
    uplPath = mybuffer[1,result]

    Am I doing something wrong? Thanks.
  • Are you running the "Set" command from a different session than OpenInsight? My understanding is that "Set" only creates a temporary environment variable for that command prompt session.
  • I am running it from a command prompt window. Len wants to be able to get such an environment variable if set, assuming it is possible.
  • Are you running the Set command first and then launching OI from the same command prompt?
  • No, I am running the set command in the Dos window, then launching OI via a bat file.
  • That won't work for the reason I already gave you. How about calling SetEnvironmentVariable from within OI, such as when application starts up?
  • Roger - Did you find a solution?
  • Hi Don.
    No, if we need to set the variable from inside OI, then we will implement a different solution using one of the OI tables. Thanks for your help anyway.
  • Maybe there still is an alternative solution. It would help to understand your use case.
  • Len wanted to use a Windows environment variable to set a file path and have a specific OI program pick up this path to use for its purpose of where to write a file being created.
  • I think that much was self-evident. But why an environment variable? How would this be set in a production environment? Is this meant to be user-controlled or something your software decides?

    The main point is that there are so many ways to identify a path to use for a program to pick up, so I'm curious as to why this approach was considered in the first place. If I understood that original rationale, it would help to suggest the best alternative or compatible solution.
Sign In or Register to comment.