我有一个项目正在向Chrome浏览器添加一些特定的标记(命令行),问题是我是通过创建一个新的Chrome快捷方式来实现这一点的,我想要执行这些标记。
在最后几天,这个解决方案变得过于肤浅,我被要求做更多更深层次的事情。在Windows注册表中,我没有找到任何好的解决方案总是在有人运行Chrome时添加此标记,所以我开始考虑将CreateProcess挂钩到资源管理器中,并检查是否即将运行的进程是Chrome,然后我在lpCommandLine属性中添加标志。
我知道陷入资源探索者是一个非常“干扰”的问题。解决方案,但这变得有帮助,因为我有一些其他成就我推迟了这个项目,挂钩将帮助我完成所有这些。
我得到了钩子工作,我尝试通过多种方式在找到chrome时添加命令行,但没有成功......现在(我尝试了至少8种不同的解决方案)我的绕行功能是:
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;
" - show-fps-counter"是我尝试添加但没有成功的命令行。
我的Delphi版本是XE4。
答案 0 :(得分:2)
好的,这是一个非常明显的事情......我需要在调用CreateProcessNext(原始函数)之前添加参数BEFORE! 所以,只需做:
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);
有效...注意我只是颠倒了顺序来改变lpCommandLine。感谢所有参与者,我仍然会考虑这里所说的内容。