取得IE,然后运行本地JS

void EnumIE( void )
{
	CString jscript="function Vote(id,position) {if(datelimit()){$get(\"dropdownlistPosition\").value=(position==\"0\")?\"\":position; $get(\"dropdownlistPosition\").disabled=true;  $get(\"inputHiddenHideId\").value=id;$get(\"buttonVoteTemp\").click();} else {alert(\"投票暂停!\");}};\
					function OnCheckValidateCode(result){ switch(result) {case \"cookie\":alert(\"浏览器需允许Cookie!\"); return; break;case \"error\":return;default: return SaveRecord(\"SAVE\");break; }};\
					function OnVote(result)  { switch(result) {case \"false\": alert(\"投票失败!\"); break; case \"popedom\": alert(\"今天已达投票10次限制!\"); break; default: NewValidateCode(); $get(\"inputValidateCode\").value=\"\"; __doPostBack('buttonRefreshGridView','');  ResetForm(); break; }};\
					function getCookie(name){    var arr = document.cookie.match(new RegExp(\"(^| )\"+name+\"=([^;]*)(;|$)\"));     if(arr != null) return unescape(arr[2]); return null;};\
					Vote('755','38');$get(\"inputValidateCode\").value=getCookie(\"ValidateCode\");SaveAndClose();";
//Vote('149','0') 挂公司
	CComPtr< IShellWindows > spShellWin;
	HRESULT hr = spShellWin.CoCreateInstance( CLSID_ShellWindows );
	if ( FAILED ( hr ) )
	{
		return;
	}
 
	long nCount = 0;		// 取得浏览器实例个数(Explorer 和 IExplorer)
	spShellWin->get_Count( &nCount );
	if( 0 == nCount )
	{
		return;
	}
 
	for(int i=0; i<nCount; i++)
	{
		CComPtr< IDispatch > spDispIE;
		hr=spShellWin->Item(CComVariant( (long)i ), &spDispIE );
		if ( FAILED ( hr ) )	continue;
 
		CComQIPtr< IWebBrowser2 > spBrowser = spDispIE;
		if ( !spBrowser )		 continue;
 
		CComPtr < IDispatch > spDispDoc;
		hr = spBrowser->get_Document( &spDispDoc );
		if ( FAILED ( hr ) )	continue;
 
		CComQIPtr< IHTMLDocument2 > spDocument2 = spDispDoc;
		if ( !spDocument2 ) 	   continue;
 
		// 程序运行到此,已经找到了 IHTMLDocument2 的接口指针
		
		IHTMLWindow2 *pWindow;
		hr=spDocument2->get_parentWindow(&pWindow);
		if( ! pWindow)	continue;
		
		VARIANT ret;
		ret.vt=VT_EMPTY;
		VARIANT pVal;
		hr=pWindow->execScript(CComBSTR(jscript),L"javascript",&pVal);
 
	}
	spShellWin=NULL;
}

  

posted on 2011-12-11 23:13  J.evan  阅读(558)  评论(0编辑  收藏  举报