版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/youkawa/article/details/15339819
在Chrome下调用其他进程,可以用注册表的形式来实现。但直接调用IE(包括其他进程),会传入一些额外的参数(如本例中的f2://douban.com),这样调用Ie的时候会出现连续嵌套调用的情况,致使调用失败。后来想了一种间接地办法,即自己写一个创建ie进程的exe文件,由chrome去调用此exe文件,exe文件对传入的参数进行了截断处理之后再把网址以参数的形式传给ie。
IEexternal.reg
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\F2]
@="URL:F2 Protocol Handler"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\F2\shell]
[HKEY_CLASSES_ROOT\F2\shell\open]
[HKEY_CLASSES_ROOT\F2\shell\open\command]
@="G:\\PAD\\Debug\\PAD.exe \"%1\""
其中“G:\\PAD\\Debug\\PAD.exe”是中间exe文件的路径,负责开启并传递网址参数给ie。%1是参数替换符,在chrome调用Ie的时候,它会被替换成“f2://网址”形式的参数。
创建好之后运行此reg文件
PAD.exe
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include <string.h>
void _tmain( int argc, char *argv[] )
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
char *p;
//TCHAR *ie_address = "\"C:\\Program Files\\Internet Explorer\\iexplore.exe\" WWW.CUC.EDU.CN";
char ie_address[100] ="\"C:\\Program Files\\Internet Explorer\\iexplore.exe\"";
char *prefix = "f2://";
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
if( argc != 2 )
{
printf("Usage: %s [cmdline]\n", argv[0]);
return;
}
p = strstr(argv[1],prefix);
if(!p)
{
// MessageBox(0,0,0,0);
return;
}
p += 5;
strcat(ie_address,p);
// Start the child process.
if( !CreateProcess( NULL, // No module name (use command line)
ie_address, // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi ) // Pointer to PROCESS_INFORMATION structure
)
{
printf( "CreateProcess failed (%d).\n", GetLastError() );
return;
}
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
}
添加书签
启用书签
点击启动应用后即可完成IE进程的调用