I'm trying to use madRemote to change a environment variable of another process, but ...
The code seems very simple:
// The function to be executed on remote process context:
Function SetEnv(params: Pointer):dword; stdcall;
If SetEnvironmentVariable('COLORS','OFF') then
//The calling procedure:
If not RemoteExecute(PH,@SetEnv,aresult,@Params,21) then
Allways return Result=1
Thanks in advance.
How to solve the problem? Something like the following code should work. Please note that single chars are not handled by Delphi as pointers, but as static ordinal values. So using the following code should be fine:
Code: Select all
Function SetEnv(params: Pointer):dword; stdcall; var str1, str2 : array [0..10] of char; Begin str1 := 'C'; str1 := 'O'; str1 := 'L'; str1 := 'O'; str1 := 'R'; str1 := 'S'; str1 := chr(0); str2 := 'O'; str2 := 'F'; str2 := 'F'; str2 := chr(0); If SetEnvironmentVariable(str1, str2) then Result:=0 Else Result:=1; End;
But after the remote function is executed successfully if I try to terminate the process by issuing a
Delphi generates a EExternalException on this line.
I the remote funcion is not executed, the terminate procedure works fine.
I hope I can exactly follow these steps through the commands.
I am following this guide: https://www.hows.tech/2019/03/how-to-se ... ws-10.html
Is there any more simpler way.