How to use or expand environment variables in a command instantiated by CreateProcess?
The following code utilizes CreateProcess to run commands with environmental variables. Here, it tries to run notepad %APPDATA%\test.txt . If I run notepad %APPDATA%\test.txt directly within Windows' CMD , %APPDATA% will be expanded. However, the environmental variable can not be expanded when executed by CreateProcess . Could you help to comment on the reason and the workaround? Any comment will be appreciated! program TestConsole2; {$APPTYPE CONSOLE} uses Windows, SysUtils; var I: Integer; ProgramName: String; StartInfo : TStartupInfo; ProcInfo : TProcessInformation; CreateOK : Boolean;