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?
Sign In or Register to comment.