How to add URL to the trusted zone in Internet Explorer?

11,408

Solution 1

The following should give you the way to do it in code...

http://blogs.msdn.com/ie/archive/2005/01/26/361228.aspx

Solution 2

MSDN

Adding Sites Programmatically

C#

Solution 3

Check this solution at CodeGuru forums.

In summary, this code uses the COM library, a library which you did say you wished to avoid. However, there is no workaround this situation. Another thing to mention is that this code is written in C++, as the guy who wrote it, CorithMartin, ported it from C#.

#include "windows.h"
#include "stdafx.h"
#include "urlmon.h"
#using <mscorlib.dll>
#include <atldef.h>
#include <atlconv.h>
using namespace System;
using namespace System::Runtime::InteropServices;
#define MAX_LOADSTRING 100

int _tmain(int argc, _TCHAR* argv[])
{
    // constants from urlmon.h
    const int URLZONE_LOCAL_MACHINE = 0;
    const int URLZONE_INTRANET = URLZONE_LOCAL_MACHINE + 1;
    const int URLZONE_TRUSTED = URLZONE_INTRANET + 1;
    const int URLZONE_INTERNET = URLZONE_TRUSTED + 1;
    const int URLZONE_UNTRUSTED = URLZONE_INTERNET + 1;
    const int URLZONE_ESC_FLAG = 0x100;
    const int SZM_CREATE  = 0;
    const int SZM_DELETE  = 0x1;

    HRESULT hr;
    IInternetSecurityManager *pSecurityMgr;
    LPCWSTR sites = SysAllocString(L"http://*.mydomain.com");

    CoInitialize(NULL);

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

    pSecurityMgr->SetZoneMapping(URLZONE_TRUSTED, sites, SZM_CREATE);

    pSecurityMgr->Release();

    return 0;
}

Solution 4

Powershell

#Setting IExplorer settings
Write-Verbose "Now configuring IE"
#Add http://website.com as a trusted Site/Domain
#Navigate to the domains folder in the registry
set-location "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
set-location ZoneMap\Domains

#Create a new folder with the website name
new-item website/ -Force
set-location website/
new-itemproperty . -Name * -Value 2 -Type DWORD -Force
new-itemproperty . -Name http -Value 2 -Type DWORD -Force
new-itemproperty . -Name https -Value 2 -Type DWORD -Force

Solution 5

It lies indeed in the registry, and it's described right there:

http://msdn.microsoft.com/en-us/library/ms537181%28VS.85%29.aspx

Beware of the UAC in Vista though. It's a real pain to deal with.

Share:
11,408
citronas
Author by

citronas

I studied computer science and math and completed my academic career with a PhD in computer science about machine learning and argument mining on text data. I've returned to the corporate sector and am currently working as a Senior Software Developer for a digital media agency where I focus on designing and implementing solutions with ASP.NET Core MVC and C#.

Updated on June 08, 2022

Comments

  • citronas
    citronas almost 2 years

    How can I add an URL to the trusted site? It seems that there are stored in the registry, but where exactly?
    The hints I've googled so far weren't helpfull.

    The .net programm will run locally on each client.

    Edit clarification: I want to do this programmaticly running C# code.