某些测试环境下, 系统用户并非管理员权限,因此当自动化脚本尝试打开一些特殊站点时,需要将站点添加到系统信任列表才可以继续访问。
利用C#和Dotnetfactory,可以实现将站点添加到IE的信任列表的功能。
1, DLL 部分实现:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;
using Microsoft.Win32;
namespace Automation
{
public class BrowserManager
{
#region AddTrustedSite
public void AddTrustedSite(string domain,string subDomian,string siteType)
{
const string domainsKeyLocation = @"Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\EscDomains";
//const string domainsKeyLocation = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains";
//const string domain = @"newsite.com";
const int trustedSiteZone = 0x2;