Reputation: 531
I have a project that was adding some specific flags (command lines) to Chrome browser, the problem is that I was doing this by creating a new Chrome shortcut, with the flags I want to execute.
In the last days this solution became too superficial, and I was requested to do something more 'deeper'. Looking on Windows Registry, I didn't found any good solution to always add this flags when someone run Chrome, so I started thinking to hook CreateProcess into explorer, and check if the process that is about to run is Chrome, then I add the flags in the lpCommandLine attribute.
I know hook into explorer is a pretty 'intrusive' solution, but this became helpful because I have some other achieves I was putting off on this project, and hooking will help me to get all them done.
I got the hook working, I tried by many ways to add the command lines when chrome is found, but no success... Right now (and I tried at least 8 different solutions) my detour function is:
function InterceptCreateProcess(lpApplicationName: PChar;
lpCommandLine: PChar;
lpProcessAttributes, lpThreadAttributes: PSecurityAttributes;
bInheritHandles: BOOL;
dwCreationFlags: DWORD;
lpEnvironment: Pointer;
lpCurrentDirectory: PChar;
const lpStartupInfo: STARTUPINFO;
var lpProcessInformation: PROCESS_INFORMATION): BOOL; stdcall;
var
Cmd: string;
begin
Result:= CreateProcessNext(lpApplicationName,
lpCommandLine,
lpProcessAttributes,
lpThreadAttributes,
bInheritHandles,
dwCreationFlags,
lpEnvironment,
lpCurrentDirectory,
lpStartupInfo,
lpProcessInformation);
if (POS(Chrome, UpperCase(String(lpApplicationName))) > 0) then
begin
Cmd:= ' --show-fps-counter';
lpCommandLine:= PChar(WideString(lpCommandLine + Cmd));
ShowMessage(lpCommandLine);
end;
end;
The "--show-fps-counter" is the command line I'm trying to add without success.
My Delphi version is XE4.
Upvotes: 2
Views: 917
Reputation: 531
Ok, this is a pretty obvious thing... I need to add the parameter BEFORE calling the CreateProcessNext (original function)! So, simply doing:
if (POS(Chrome, UpperCase(String(lpApplicationName))) > 0) then
begin
lpCommandLine:= PChar(lpCommandLine + ' --show-fps-counter');
end;
Result:= CreateProcessNext(lpApplicationName,
lpCommandLine,
lpProcessAttributes,
lpThreadAttributes,
bInheritHandles,
dwCreationFlags,
lpEnvironment,
lpCurrentDirectory,
lpStartupInfo,
lpProcessInformation);
works... note that I just inverted the order to change the lpCommandLine. Thank's for all participants and I'll still consider what was said here.
Upvotes: 2