1、打开 Microsoft .NET Framework 2.0 Configuration 控制台程序(如果有多个 fx 版本只更改最新的即可)
2、运行库安全策略
3、计算机
4、代码组
5、右键 All_code -新建-数据新建代码组名称-下一步--代码组权限类型选择“URL”--下面的URL中输入URL 地址,例如:http://192.168.0.1/*
6、使用现有权限集选择”FullTrust"---确定。
7、重新启动计算机。
二、这样操作也挺麻烦的,所以阿又经过对“%Systemroot%\Microsoft.NET\Framework”目录中文件的研究发现有一个命令可以来做这些活:CasPol.exe
例如:
caspol-quiet -machine -addgroup All_Code -url http://localhost/* FullTrust -n OGTLogDBMS -d 测井数据库系统程序访问授权控制
三、如果写一个程序来做不是更简单了。
下面是代码:
public override voidInstall(IDictionary stateSaver)
{
//MessageBox.Show( "OK" );
base.Install(stateSaver);
StringDictionary parameters = Context.Parameters;
string hostnamestr = parameters["hostname"];
if (hostnamestr == null || hostnamestr == "")
{
this.Rollback(null);
}
else
{
//MessageBox.Show( str.ToString() );
string[] fxs = this.UpToTheMinuteFX();
if (fxs != null && fxs.Length != 0)
{
foreach (string fxpath in fxs)
{
string fxpathtemp = fxpath + "\\caspol.exe";
if (File.Exists(fxpathtemp))
{
//MessageBox.Show( fxpathtemp.ToString() );
this.startexe(fxpathtemp.Trim(),
hostnamestr.Trim() + "/*");
}
}
}
}
}
/// <summary>
/// 添加代码组权限
/// </summary>
/// <param name="exepath">Caspol.exe 程序的路径</param>
/// <param name="url">代码组的 url 地址</param>
private void startexe(string exepath, string url)
{
//声明一个程序信息类
System.Diagnostics.ProcessStartInfo Info = new
System.Diagnostics.ProcessStartInfo();
//设置外部程序名
Info.FileName = exepath;
//设置外部程序的启动参数(命令行参数)为 test.txt
Info.Arguments = "-quiet -machine -addgroup All_Code -url " + url + " FullTrust -n OGTLogDBMS -d 测井数据库系统程序访问授权控制";
//设置外部程序工作目录为 C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
//Info.WorkingDirectory = @"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727";
//声明一个程序类
System.Diagnostics.Process Proc;
try
{
//启动外部程序
Proc = System.Diagnostics.Process.Start(Info);
}
catch (System.ComponentModel.Win32Exception ee)
{
MessageBox.Show("系统找不到指定的程序文件。", ee.ToString());
return;
}
//如果这个外部程序没有结束运行则对其强行终止
if (Proc.HasExited == false)
{
//Console.WriteLine("由主程序强行终止外部程序的运行!");
//Proc.Kill();
}
else
{
//Console.WriteLine("由外部程序正常退出!");
}
}
// <summary>
// 获取最各个版本的 Framework目录。
// </summary>
// <returns></returns>
private string[] UpToTheMinuteFX()
{
//调用 GetWindowsDirectory 取得 Windows 路径
const int nchars = 128;
StringBuilder Buff = new StringBuilder(nchars);
GetWindowsDirectory(Buff, nchars);
string fxstr = Buff.ToString();
fxstr = fxstr + @"\Microsoft.NET\Framework";
string[] fxstrs = Directory.GetDirectories(fxstr);
if (fxstrs != null && fxstrs.Length != 0)
return fxstrs;
return null;
}
四、由于写作水平和编程水平有限本文不妥之处请纠正。






