LZ参考一下Caspol工具,也可用.NET配置工具配置安全性

解决方案 »

  1.   

    也可以在别人的机子上打开.net DOS命令
    输入
     caspol -u -ag All_Code -url "该程序的目录\*" FullTrust -n MYDIR1
      

  2.   

    可以,写个安装类就OK了,不会叫我写吧?
    获得Caspol.exe路径
    获得安装路径
    然后也就不用我说了吧!
      

  3.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Configuration.Install;
    using System.Runtime.InteropServices;
    using Microsoft.VisualStudio.Tools.Applications.Runtime ;
    using System.Windows.Forms;
    using System.Text;
    namespace DLSetupAction
    {
        [RunInstaller(true)]
        public partial class DLInstaller : Installer
        {
            public DLInstaller()
            {
                InitializeComponent();
                this.BeforeInstall += new InstallEventHandler(DLInstaller_BeforeInstall);
                this.AfterInstall += new InstallEventHandler(DLInstaller_AfterInstall);
            }        public override void Install(System.Collections.IDictionary stateSaver)
            {
                base.Install(stateSaver);
            }        [DllImport("mscoree.dll")]
            internal static extern void GetCORSystemDirectory([MarshalAs(UnmanagedType.LPTStr)] System.Text.StringBuilder buffer, int bufferLength, ref int length);        private void DLInstaller_AfterInstall(object sender, InstallEventArgs e)
            {
                //获得Caspol工具所在的文件路径
                System.Text.StringBuilder sPath = new System.Text.StringBuilder(1024);
                int size = 0;
                
                GetCORSystemDirectory(sPath, sPath.Capacity, ref size);
                sPath.Append("Caspol.exe");
                
                //获得安装程序的目标路径
                
                    string sUrl = this.Context.Parameters["targetdir"].Trim('/');                                         sUrl += "*";
               
                //设置Caspol的命令参数
                StringBuilder sPar = new StringBuilder("-q -u -ag All_Code -url");
                //sPar.Append(sUrl);
                sPar.Append(" FullTrust");
                sPar.Append(" -n");
                sPar.Append(" myexcelapp");
                
                //执行Caspol命令来配置权限
               System.Diagnostics.Process.Start(sPath.ToString(), sPar.ToString()); 
            }        private void DLInstaller_BeforeInstall(object sender, InstallEventArgs e)
            {
                //获得Caspol工具所在的文件路径
                System.Text.StringBuilder sPath = new System.Text.StringBuilder(1024);
                int size = 0;
                GetCORSystemDirectory(sPath, sPath.Capacity, ref size);
                sPath.Append("Caspol.exe");
                //执行Caspol命令来取消权限
                System.Diagnostics.Process.Start(sPath.ToString(), "-q -u -rg myexcelapp"); 
            }
        }
    }