Skip to content

Latest commit

 

History

History
51 lines (37 loc) · 1.3 KB

sample_132.md

File metadata and controls

51 lines (37 loc) · 1.3 KB

Home

检索环境字符串的另一种方法

翻译:xinjie 2022.01.30

开始之前:

参看:


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#")  

函数列表:

ExpandEnvironmentStrings

备注:

如果没有对应的环境变量,该函数返回输入的参数。