WebConfig ConnectionStrings Tool For .NET2.0

原创 2007年09月27日 20:28:00

App.xml

<?xml version="1.0" encoding="utf-8" ?>
<app>
  <add key = "1" value="C:/WIndows/Microsoft.NET/Framework/v2.0.50727/aspnet_regiis.exe"/>
  <add key = "2" value="MyKeys"/>
  <add key = "3" value="/Demo"/><!--虛擬目錄路徑-->
  <add key = "4" value="ecnc0048/ASPNET"/> <!--ASPNET帳號-->
</app>

C# Code: 

static void Main(string[] args)
        {
            Console.Title = "WebConfig ConnectionStrings Tool For .NET2.0";
            Console.WriteLine("WebConfig ConnectionStrings Encryption and Declassified Tool/n");

            Console.WriteLine("1)Encryption WebConfig ConnectionStrings.");
            Console.WriteLine("2)Declassified WebConfig ConnectionStrings.");
            Console.WriteLine("3)Exit WebConfig./n");
            Console.Write("Please select number: ");

            string strIn = Console.ReadLine().Replace("Please select number:", "");
            switch (strIn)
            {
                case "1"://加密
                    RunCmd("1");
                    break;
                case "2"://解密
                    RunCmd("2");
                    break;
                case "3"://退出
                    break;
                default:
                    Console.WriteLine("/n Input error./n");               
                    Main(args);
                    break;
            }

            //Console.WriteLine(RunCmd(@"C:/WIndows/Microsoft.NET/Framework/v2.0.50727/aspnet_regiis -pc MyKeys -exp"));
            //Console.WriteLine(RunCmd(@"C:/WIndows/Microsoft.NET/Framework/v2.0.50727/aspnet_regiis -pe connectionStrings -app /Demo"));
            //Console.WriteLine(RunCmd(@"C:/WIndows/Microsoft.NET/Framework/v2.0.50727/aspnet_regiis -pa NetFrameworkConfigurationKey ecnc0048/ASPNET"));
            //Console.WriteLine(RunCmd(@"C:/WIndows/Microsoft.NET/Framework/v2.0.50727/aspnet_regiis -pa MyKeys ecnc0048/ASPNET"));
        }

        private static void RunCmd(string select)
        {
            string xmlFile = System.IO.Path.GetFullPath(@"App.xml");
            if (File.Exists(xmlFile))
            {
                XmlDocument xDoc = new XmlDocument();
                xDoc.Load(xmlFile);
                XmlNode xNode;
                XmlElement xElem1, xElem2, xElem3, xElem4;

                xNode = xDoc.SelectSingleNode("//app");
                xElem1 = (XmlElement)xNode.SelectSingleNode("//add[@key='1']");
                xElem2 = (XmlElement)xNode.SelectSingleNode("//add[@key='2']");
                xElem3 = (XmlElement)xNode.SelectSingleNode("//add[@key='3']");
                xElem4 = (XmlElement)xNode.SelectSingleNode("//add[@key='4']");

                if (xElem1 != null)
                {
                    string command = xElem1.GetAttribute("value");
                    string cmdKey = xElem2.GetAttribute("value");
                    string iisPath = xElem3.GetAttribute("value");
                    string iisUser = xElem4.GetAttribute("value");

                    if (File.Exists(command))
                    {
                        if (select == "1")
                        {
                            cmd(command + " -pc " + cmdKey + " -exp");
                            cmd(command + " -pe connectionStrings -app " + iisPath);
                            cmd(command + " -pa NetFrameworkConfigurationKey " + iisUser);
                            cmd(command + " -pa " + cmdKey + " " + iisUser);
                        }
                        else if (select == "2")
                        {
                            cmd(command + " -pd connectionStrings -app " + iisPath);
                        }

                        Console.WriteLine("Please Enter Exit.");
                        Console.ReadLine();
                    }
                    else
                    {
                        Console.WriteLine(command + " file does not exist.");
                        Console.WriteLine("Please check App.xml file./n");
                        Main(null);
                        return;
                    }
                }
            }
            else
            {
                Console.WriteLine("App.XML file does not exist./n");
                Main(null);
                return;
            }
        }

        private static void cmd(string command)
        {
            Process p = new Process();
            p.StartInfo.FileName = "cmd.exe";           //指定程序名
            p.StartInfo.Arguments = "/c " + command;    //定程式
            p.StartInfo.UseShellExecute = false;        //Shell的使用
            p.StartInfo.RedirectStandardInput = true;   //重定向入
            p.StartInfo.RedirectStandardOutput = true;  //重定向出
            p.StartInfo.RedirectStandardError = true;   //重定向出
            p.StartInfo.CreateNoWindow = true;          //置不示窗口

            p.Start();   //€€€€

            //p.StandardInput.WriteLine(command);       
            //p.StandardInput.WriteLine("exit");      
            //return p.StandardOutput.ReadToEnd();        
            Console.WriteLine(p.StandardOutput.ReadToEnd());
        }

相关文章推荐

会员积分系统 for asp.net2.0

  • 2007年04月25日 17:59
  • 654KB
  • 下载

用asp.net2.0开发的for循环结构

  • 2009年12月02日 17:19
  • 2KB
  • 下载

ASP.NET2.0 SQL Server数据库连接详解

今天学习建立ASP.NET 与SQL Server数据库建立连接的方法,在网上搜到一片好文章,果断收藏了!共勉!            文将详细介绍如何使用Connection对象连接数据库 。对于不...

asp.net2.0导出pdf文件完美解决方案

PDF简介:PDF(Portable Document Format)文件格式是Adobe公司开发的电子文件格式。这种文件格式与操作系统平台无关,也就是说,PDF文件不管是在Windows,Unix还...

FastReport.Net V2013.2.5 For .Net2.0 破解版

  • 2017年07月03日 14:23
  • 15.74MB
  • 下载

SAP .net Connector 3.0.6 X86 for .net2.0

  • 2012年03月09日 15:20
  • 7.44MB
  • 下载

ASP.NET2.0文件图片处理

1.最简单的单文件上传(没花头) 2.多文件上传 3.客户端检查上传文件类型(以上传图片为例) 4.服务器端检查上传文件类型(以上传图片为例) 5.服务器端检查上传文件类型(可以检测真正文...

C# .net2.0中使用扩展方法和lambda表达式

虽然这两个东西都是C#3.0才有的语法 但是因为.net 2.0-3.5是同一个CLR版本 而扩展方法和λ表达式本身也是一种语法糖 所以 在.net2.0中能够使用上述语法 看上去就是”理所当然“...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:WebConfig ConnectionStrings Tool For .NET2.0
举报原因:
原因补充:

(最多只允许输入30个字)