Se me ocurre algo como esto:
Código Delphi
[-]
function InsertarVariables(Str: String): String;
var
i: Integer;
EnvBlock, P: PChar;
begin
Result:= Str;
EnvBlock:= GetEnvironmentStrings;
if EnvBlock <> nil then
try
with TStringList.Create do
try
P:= EnvBlock;
while P^ <> #0 do
begin
if Pos('=',String(P)) > 1 then
Add(String(P));
inc(P,StrLen(P)+1);
end;
for i:= 0 to Count - 1 do
Result:= StringReplace(Result,'%'+ Names[i] +'%', ValueFromIndex[i],
[rfIgnoreCase,rfReplaceAll]);
finally
Free;
end;
finally
FreeEnvironmentStrings(EnvBlock);
end;
end;
ShowMessage(InsertarVariables('%Windir%\miprograma.exe'));