Clarion
Get the Environment Variables (Clarion 5.5+)

In this sample we read the Environment Variables into Clarion. Its based on a snippet from Michael Ziegler. I made a working APP from that.

First go to the Global Embeds. In the embed Global Data you find a lot of declared variables, each one has an "ENV:" as a prefix. Adding so many of them was easier this way rather than inserting the variables with the Property Editor.
Note: Mark Goldberg pointed out that a length of 201 is likely a tad too short for the value of PATH. So consider to increase the size accordingly. I did not modify the example APP because for that I would have to dig for that older Clarion version and install it again.

ENV:ALLUSERSPROFILE   CSTRING(201)
ENV:APPDATA           CSTRING(201)
ENV:CLIENTNAME        CSTRING(201)
...	

They all got the same length, no matter if it was needed or not - its a sample....! ;-)

Now Inside the Global Map you find

MODULE('Windows.DLL')
  GetEnvironmentVariableA (*CSTRING, *CSTRING, ULONG),ULONG,PASCAL,RAW
END

GetEnv (STRING),STRING	

The code of the procedure GetEnv() is to be found in Program Procedures and looks like this:

GetEnv PROCEDURE(str)
cres CSTRING(201)
cstr CSTRING(201)
len LONG
  CODE
  cstr = clip(str)
  len = GetEnvironmentVariableA (cstr, cres, size(cres)-1)
  return clip(cres)	

This means we will be able to access GetEnv() in our entire application. You see this in the INIT of the window where we call a routine with

DO ReadEnvironment

which is to be found in the Procedures Routines. All previously defined global variables are assigned here like this:

ENV:ALLUSERSPROFILE        = GetEnv('ALLUSERSPROFILE')
ENV:APPDATA                = GetEnv('APPDATA')
ENV:CLIENTNAME             = GetEnv('CLIENTNAME')
	....

The purpose why I wanted to read those data was to identify a workstation as a CITRIX-client. Each workstation has the same ComputerName so that one was not helpful. Paul Howard pointed me to CLIENTNAME to be unique in this case. If not under CITRIX, the CLIENTNAME is either empty or it is 'Console'. When you include CWUTIL.INC you can even use IsTermServer() for detection.

I took the Environments Variables from Windows XP to display in this example (see below). Other versions of Windows have other (and maybe less) of them. If such an Environment Variable does not exist the Clarion variable remains empty.

Thats mostly all! Add salt and pepper as you like....

You can download the .APP-file.

Sample uploaded: 22. April 2007


Here you find some more samples


The variables and equates I used for the EnviromentVariables I found in XP:

ALLUSERSPROFILE CSTRING(201)
APPDATA CSTRING(201)
CLIENTNAME CSTRING(201)
CommonProgramFiles CSTRING(201)
COMPUTERNAME CSTRING(201)
ComSpec CSTRING(201)
FP_NO_HOST_CHECK CSTRING(201)
HOMEDRIVE CSTRING(201)
HOMEPATH CSTRING(201)
LOGONSERVER CSTRING(201)
NUMBER_OF_PROCESSORS CSTRING(201)
OS CSTRING(201)
Path CSTRING(201)
PATHEXT CSTRING(201)
PROCESSOR_ARCHITECTURE CSTRING(201)
PROCESSOR_IDENTIFIER CSTRING(201)
PROCESSOR_LEVEL CSTRING(201)
PROCESSOR_REVISION CSTRING(201)
ProgramFiles CSTRING(201)
PROMPT CSTRING(201)
SESSIONNAME CSTRING(201)
SystemDrive CSTRING(201)
SystemRoot CSTRING(201)
TEMP CSTRING(201)
TMP CSTRING(201)
USERDOMAIN CSTRING(201)
USERNAME CSTRING(201)
USERPROFILE CSTRING(201)
windir CSTRING(201)




ENV:ALLUSERSPROFILE = GetEnv('ALLUSERSPROFILE')
ENV:APPDATA = GetEnv('APPDATA')
ENV:CLIENTNAME = GetEnv('CLIENTNAME')
ENV:CommonProgramFiles = GetEnv('CommonProgramFiles')
ENV:COMPUTERNAME = GetEnv('COMPUTERNAME')
ENV:ComSpec = GetEnv('ComSpec')
ENV:FP_NO_HOST_CHECK = GetEnv('FP_NO_HOST_CHECK')
ENV:HOMEDRIVE = GetEnv('HOMEDRIVE')
ENV:HOMEPATH = GetEnv('HOMEPATH')
ENV:LOGONSERVER = GetEnv('LOGONSERVER')
ENV:NUMBER_OF_PROCESSORS = GetEnv('NUMBER_OF_PROCESSORS')
ENV:OS = GetEnv('OS')
ENV:Path = GetEnv('Path')
ENV:PATHEXT = GetEnv('PATHEXT')
ENV:PROCESSOR_ARCHITECTURE = GetEnv('PROCESSOR_ARCHITECTURE')
ENV:PROCESSOR_IDENTIFIER = GetEnv('PROCESSOR_IDENTIFIER')
ENV:PROCESSOR_LEVEL = GetEnv('PROCESSOR_LEVEL')
ENV:PROCESSOR_REVISION = GetEnv('PROCESSOR_REVISION')
ENV:ProgramFiles = GetEnv('ProgramFiles')
ENV:PROMPT = GetEnv('PROMPT')
ENV:SESSIONNAME = GetEnv('SESSIONNAME')
ENV:SystemDrive = GetEnv('SystemDrive')
ENV:SystemRoot = GetEnv('SystemRoot')
ENV:TEMP = GetEnv('TEMP')
ENV:TMP = GetEnv('TMP')
ENV:USERDOMAIN = GetEnv('USERDOMAIN')
ENV:USERNAME = GetEnv('USERNAME')
ENV:USERPROFILE = GetEnv('USERPROFILE')
ENV:windir = GetEnv('windir')


MODULE('Windows.DLL')
GetEnvironmentVariableA (*CSTRING, *CSTRING, ULONG),ULONG,PASCAL,RAW
END

GetEnv (STRING),STRING

GetEnv PROCEDURE(str)
cres CSTRING(201)
cstr CSTRING(201)
len LONG
CODE
cstr = clip(str)
len = GetEnvironmentVariableA (cstr, cres, size(cres)-1)
return clip(cres)



The result from SET in the DOS-Box on Windows 7

Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. Alle Rechte vorbehalten.

C:\Users\Wolfgang>set
ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\Wolfgang\AppData\Roaming
CommonProgramFiles=C:\Program Files\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
CommonProgramW6432=C:\Program Files\Common Files
COMPUTERNAME=SEPTIMUS
ComSpec=C:\Windows\system32\cmd.exe
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
HOMEPATH=\Users\Wolfgang
LOCALAPPDATA=C:\Users\Wolfgang\AppData\Local
LOGONSERVER=\\SEPTIMUS
NUMBER_OF_PROCESSORS=4
OS=Windows_NT
Path=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32
\WindowsPowerShell\v1.0\
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE=AMD64
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 23 Stepping 10, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=170a
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
ProgramFiles(x86)=C:\Program Files (x86)
ProgramW6432=C:\Program Files
PROMPT=$P$G
PSModulePath=C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
PUBLIC=C:\Users\Public
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\Windows
TEMP=C:\Users\Wolfgang\AppData\Local\Temp
TMP=C:\Users\Wolfgang\AppData\Local\Temp
USERDOMAIN=Septimus
USERNAME=Wolfgang
USERPROFILE=C:\Users\Wolfgang
VBOX_INSTALL_PATH=C:\Program Files\Sun\VirtualBox\
windir=C:\Windows

C:\Users\Wolfgang>