1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > IE浏览器之可信任站点

IE浏览器之可信任站点

时间:2022-03-16 18:24:05

相关推荐

IE浏览器之可信任站点

// AddTrustSite.cpp : Defines the entry point for the application.

//一个网站当被某个客户端认为是可信站点后,从该站点下载的网页控件将被客户端信任且运行,那如何向客户端增加可信站点,是一项技术。

//传统的办法是直接操作注册表。但是据我研究,在winXP和win及winVista上,可信站点列表在注册表中的位置并不相同,且根据ie的不同版本,该位置也有不少差异。

//因此如果在不同平台和ie版本上增加可信站点,需要大量的判断。

//这里给出了一个办法,是直接调用ie的com组件,通过该com组件的接口,向系统中直接添加可信站点,且不被系统中是否为https站点的限制。

//编译后,支持命令行的方式运行。运行方式为:” AddTrustSite.exe ”

//#include “urlmon.h”

#include “windows.h”

#include “stdio.h”

bool AddTrustSite(LPCTSTR lpSiteName);

int APIENTRY WinMain(HINSTANCE hInstance,

HINSTANCE hPrevInstance,

LPSTR lpCmdLine,

int nCmdShow)

{

if(AddTrustSite(lpCmdLine))

{

MessageBox(NULL, “AddTrustSite success!”, “Note”, MB_OK | MB_ICONEXCLAMATION);

}

else

{

MessageBox(NULL, “AddTrustSite failed!”, “Note”, MB_OK | MB_ICONEXCLAMATION);

}

return 0;

}

bool AddTrustSite(LPCTSTR lpSiteName)

{

HRESULT hr;

IInternetSecurityManager *pSecurityMgr;

IInternetZoneManager *pZoneMgr;

int iUnicodeLen = 0;

WCHAR *pwcharUnicode = NULL;

ZONEATTRIBUTES zoneAttributes;

LPWSTR lpTrustSite = NULL;

#ifdef _UNICODE

lpTrustSite = SysAllocString(lpSiteName);

#else

iUnicodeLen = MultiByteToWideChar(CP_ACP, 0, lpSiteName, strlen(lpSiteName), NULL, 0);

if(iUnicodeLen < 1)

{

return false;

}

pwcharUnicode = new WCHAR[iUnicodeLen+1];memset(pwcharUnicode, 0x00, sizeof(WCHAR)*(iUnicodeLen+1));if(iUnicodeLen != MultiByteToWideChar(CP_ACP, 0, lpSiteName, strlen(lpSiteName), pwcharUnicode, iUnicodeLen)){if(pwcharUnicode != NULL){delete [] pwcharUnicode;pwcharUnicode = NULL;}return false;}

lpTrustSite = SysAllocString(pwcharUnicode);

#endif

::CoInitialize(NULL);

hr = CoCreateInstance(CLSID_InternetSecurityManager, NULL, CLSCTX_INPROC_SERVER, IID_IInternetSecurityManager, (void**)&pSecurityMgr);

hr = CoCreateInstance(CLSID_InternetZoneManager,NULL,CLSCTX_INPROC_SERVER,IID_IInternetZoneManager,(void**)&pZoneMgr);

pZoneMgr->GetZoneAttributes((DWORD)2,&zoneAttributes);if((zoneAttributes.dwFlags & ZAFLAGS_REQUIRE_VERIFICATION) == ZAFLAGS_REQUIRE_VERIFICATION){zoneAttributes.dwFlags &= ~ZAFLAGS_REQUIRE_VERIFICATION;pZoneMgr->SetZoneAttributes((DWORD)URLZONE_TRUSTED,&zoneAttributes);pSecurityMgr->SetZoneMapping((DWORD)URLZONE_TRUSTED, lpTrustSite, (DWORD)SZM_CREATE );zoneAttributes.dwFlags |= ZAFLAGS_REQUIRE_VERIFICATION;pZoneMgr->SetZoneAttributes((DWORD)URLZONE_TRUSTED,&zoneAttributes);}else{pSecurityMgr->SetZoneMapping((DWORD)URLZONE_TRUSTED, lpTrustSite, (DWORD)SZM_CREATE );}pSecurityMgr->Release();pZoneMgr->Release();

SysFreeString(lpTrustSite);

if(pwcharUnicode != NULL){delete [] pwcharUnicode;pwcharUnicode = NULL;}

::CoUninitialize();

return true;

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。