Skip to content

Latest commit

 

History

History
49 lines (36 loc) · 1.33 KB

File metadata and controls

49 lines (36 loc) · 1.33 KB

Home

One more way to retrieve environment strings

Before you begin:

See also:


Code:

DECLARE INTEGER ExpandEnvironmentStrings IN kernel32;
	STRING   lpSrc,;
	STRING @ lpDst,;
	INTEGER  nSize

? "COMPSPEC=",     getVar ("%comspec%")
? "COMPUTERNAME=", getVar ("%computername%")
? "USERDOMAIN=",   getVar ("%userdomain%")
? "USERNAME=",     getVar ("%username%")
? "USERPROFILE=",  getVar ("%userprofile%")
? "SYSTEMROOT=",   getVar ("%systemroot%")
? "TEMP=",         getVar ("%temp%")
? "TMP=",          getVar ("%tmp%")
? "PATH=",         getVar ("%path%")

FUNCTION  getVar (lcVarname)
	LOCAL lnBufferSize, lcResult
	lnBufferSize = 2048
	lcResult = SPACE(lnBufferSize)
	lnResult = ExpandEnvironmentStrings (lcVarname, @lcResult, lnBufferSize)
RETURN IIF(lnResult > 0, LEFT(lcResult, AT(Chr(0), lcResult)-1), "#nothing#")  

Listed functions:

ExpandEnvironmentStrings

Comment:

If there is no corresponding environment variable, this function returns the input parameter unchanged.