【发布时间】:2010-03-18 15:22:07
【问题描述】:
如何将 URL 添加到受信任的站点?好像有存储在注册表中,但具体在哪里呢?
到目前为止我在谷歌上搜索的提示没有帮助。
.net 程序将在每个客户端本地运行。
编辑说明:我想以编程方式运行 C# 代码。
【问题讨论】:
标签: c# asp.net internet-explorer trusted-sites
如何将 URL 添加到受信任的站点?好像有存储在注册表中,但具体在哪里呢?
到目前为止我在谷歌上搜索的提示没有帮助。
.net 程序将在每个客户端本地运行。
编辑说明:我想以编程方式运行 C# 代码。
【问题讨论】:
标签: c# asp.net internet-explorer trusted-sites
以下内容应为您提供在代码中执行此操作的方法...
【讨论】:
它确实存在于注册表中,并且在那里进行了描述:
http://msdn.microsoft.com/en-us/library/ms537181%28VS.85%29.aspx
但请注意 Vista 中的 UAC。处理起来真的很痛苦。
【讨论】:
在 CodeGuru 论坛上查看此 solution。
总之,这段代码使用了 COM 库,您确实说过希望避免使用该库。但是,没有解决这种情况的方法。另一件要提的是,这段代码是用 C++ 编写的,因为编写它的人 CorithMartin 是从 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;
}
【讨论】:
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
【讨论】:
要添加新的受信任区域,它会在路径上创建区域注册表项和文件夹 HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains 它为每个域创建一个新的 带域名的密钥 (sample.com) 在这个带有子域 (www) 的新密钥下 并在这个下一个带有方案名称的新 REG_DWORD(http 或 https) 十六进制值 2 就是这样,你搞定了
【讨论】:
这是一种简化流程的方法。
设置 regFile="C:\TempTS\AddTrustedSiteTS.reg"
ECHO Windows 注册表编辑器版本 5.00 > %regFile%
ECHO [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\MySecureDomain.com\www] >> %regFile
ECHO "https"=dword:00000002 >> %regFile%
regedit /s %regFile%
删除 %regFile%
ECHO [HKEY_CURRENT_USER... 和 ECHO "https"... 行可以针对每个检查的提供商重复。对于“ALL”提供程序,使用星号代替“https”,如下所示:
ECHO [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet 设置\ZoneMap\Domains\MySecureDomain.com\www] >> %regFile% ECHO "*"=dword:00000002 >> %regFile%
使用此调用运行 .bat 文件:
System.Diagnostics.Process.Start("C:\TempTS\AddTrustedSites.bat")
.bat 文件运行后(只需几微秒),删除 bat 文件和 tempTS 目录。
麦克斯普斯特
(又名 GNoter,TechStuffBC)
===========================
信用到期:
regedit /s AddTrustedSite.reg
“/s”将抑制确认对话框
还有:
见http://www.computing.net/answers/windows-xp/bat-file-to-add-trusted-site-in-ie/139995.html
【讨论】: