Программно добавьте надежные сайты к Internet Explorer

Попробуй это.

var datetime = new Date().toJSON().slice(0,10) 
    + " " + new Date(new Date()).toString().split(' ')[4];

console.log(datetime);
11
задан Even Mien 9 June 2009 в 20:33
поделиться

5 ответов

Взгляните на этот

По сути, все, что вам нужно сделать, это создать раздел реестра в

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\DOMAINNAME

, а затем значение REG_DWORD с именем "http" со значением = = 2

13
ответ дан 3 December 2019 в 02:02
поделиться

Здесь ' s реализация, которую я придумал для написания ключей реестра в .NET.

Спасибо, что указали мне правильное направление, Бен.

using System;
using System.Collections.Generic;
using Microsoft.Win32;


namespace ReportManagement
{
    class ReportDownloader
    {
        [STAThread]
        static void Main(string[] args)
        {

            const string domainsKeyLocation = @"Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains";
            const string domain = @"newsite.com";
            const int trustedSiteZone = 0x2;

            var subdomains = new Dictionary<string, string>
                                 {
                                     {"www", "https"},
                                     {"www", "http"},
                                     {"blog", "https"},
                                     {"blog", "http"}
                                 };

            RegistryKey currentUserKey = Registry.CurrentUser;

            currentUserKey.GetOrCreateSubKey(domainsKeyLocation, domain, false);

            foreach (var subdomain in subdomains)
            {
                CreateSubdomainKeyAndValue(currentUserKey, domainsKeyLocation, domain, subdomain, trustedSiteZone);
            }

            //automation code
        }

        private static void CreateSubdomainKeyAndValue(RegistryKey currentUserKey, string domainsKeyLocation, 
            string domain, KeyValuePair<string, string> subdomain, int zone)
        {
            RegistryKey subdomainRegistryKey = currentUserKey.GetOrCreateSubKey(
                string.Format(@"{0}\{1}", domainsKeyLocation, domain), 
                subdomain.Key, true);

            object objSubDomainValue = subdomainRegistryKey.GetValue(subdomain.Value);

            if (objSubDomainValue == null || Convert.ToInt32(objSubDomainValue) != zone)
            {
                subdomainRegistryKey.SetValue(subdomain.Value, zone, RegistryValueKind.DWord);
            }
        }
    }

    public static class RegistryKeyExtensionMethods
    {
        public static RegistryKey GetOrCreateSubKey(this RegistryKey registryKey, string parentKeyLocation, 
            string key, bool writable)
        {
            string keyLocation = string.Format(@"{0}\{1}", parentKeyLocation, key);

            RegistryKey foundRegistryKey = registryKey.OpenSubKey(keyLocation, writable);

            return foundRegistryKey ?? registryKey.CreateSubKey(parentKeyLocation, key);
        }

        public static RegistryKey CreateSubKey(this RegistryKey registryKey, string parentKeyLocation, string key)
        {
            RegistryKey parentKey = registryKey.OpenSubKey(parentKeyLocation, true); //must be writable == true
            if (parentKey == null) { throw new NullReferenceException(string.Format("Missing parent key: {0}", parentKeyLocation)); }

            RegistryKey createdKey = parentKey.CreateSubKey(key);
            if (createdKey == null) { throw new Exception(string.Format("Key not created: {0}", key)); }

            return createdKey;
        }
    }
}
10
ответ дан 3 December 2019 в 02:02
поделиться

Рад, что я наткнулся на ваши сообщения. Единственное, что я могу добавить к уже имеющимся отличным вкладам, это то, что другой ключ реестра используется всякий раз, когда URI содержит IP-адрес, то есть адрес не является полностью определенным доменным именем.

В этом случае вы должны использовать альтернативный подходить: Строка с именем «: Range» со значением «10.0.1.13»

6
ответ дан 3 December 2019 в 02:02
поделиться

If a website could add itself to the trusted sites, now that would be bad.

I don't quite agree- as long as the browser asks the user for permission, the ability of a site to add itself to trusted sites can greatly simplify the user experience, where the user trusts the domain and wants correct page display.

The alternative is the user must manually go into internet options to add the domain, which is, for my users, not viable.

i'm looking for a php or javascript method for the site to add itself, either through some IE api, or through the registry as you've so helpfully explained above!

have found these possible solutions so far:

  • php via shell
  • others i'm not allowed to list here because i don't have enough points
-1
ответ дан 3 December 2019 в 02:02
поделиться

В дополнение к добавлению домена в список надежных сайтов вам также может потребоваться изменить настройку «Автоматически запрашивать загрузку файлов» для зоны «Надежные сайты». Чтобы сделать это программно, вы изменяете ключ/значение:

HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Настройки\Зоны\2@2200

Измените значение с 3 (Отключить) на 0 (Включить). Вот код C# для этого:

public void DisableForTrustedSitesZone()
{
    const string ZonesLocation = @"Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones";
    const int TrustedSiteZone = 2;

    const string AutoPromptForFileDownloadsValueName = @"2200";
    const int AutoPromptForFileDownloadsValueEnable = 0x00;     // Bypass security bar prompt

    using (RegistryKey currentUserKey = Registry.CurrentUser)
    {
        RegistryKey trustedSiteZoneKey = currentUserKey.OpenSubKey(string.Format(@"{0}\{1:d}", ZonesLocation, TrustedSiteZone), true);
        trustedSiteZoneKey.SetValue(AutoPromptForFileDownloadsValueName, AutoPromptForFileDownloadsValueEnable, RegistryValueKind.DWord);
    }
}
2
ответ дан 3 December 2019 в 02:02
поделиться
Другие вопросы по тегам:

Похожие вопросы: