C# 批量新建网站 IIS服务器

C# 批量新建网站 IIS服务器, 循环创建多个网站

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            // 循环创建多个网站
            string[] lines = File.ReadAllLines(Path.Combine(Application.StartupPath, "网站名称.txt"));
            foreach (string line in lines)
            {
                if (string.IsNullOrEmpty(line) || line.Trim() == "") continue;
                string name = line.Trim();

                string siteName = "5ADanCi_" + name;
                string sitePath = "C:\\5ADanCi_Batch\\" + name;
                if (!Directory.Exists(sitePath)) { Directory.CreateDirectory(sitePath); }
                string appPoolName = siteName + "_Pool";

                // 使用 appcmd 命令创建网站
                string command = $"add site /name:{siteName} /bindings:http://{name}.5adanci.com:80 /physicalPath:{sitePath}";
                ExecuteAppCmd(command);

                command = $"add apppool /name:{appPoolName}  /managedRuntimeVersion:\"v4.0\" /managedPipelineMode:\"Integrated\"";
                ExecuteAppCmd(command);

                // 设置网站的应用程序池
                command = $"set app /app.name:{siteName}/ /applicationPool:{appPoolName}";
                ExecuteAppCmd(command);
            }
            MessageBox.Show("OK");
        }

        // 执行 appcmd 命令的方法
        private void ExecuteAppCmd(string command)
        {
            textBox1.Text += command + "\r\n";
            Process process = new Process();
            ProcessStartInfo startInfo = new ProcessStartInfo
            {
                FileName = "C:\\Windows\\System32\\inetsrv\\appcmd.exe",
                Arguments = command,
                RedirectStandardOutput = true,
                UseShellExecute = false,
                CreateNoWindow = true
            };

            process.StartInfo = startInfo;
            process.Start();
            process.WaitForExit();
        }
批量修改文件名 2024年最新版 完全免费
批量修改文件名称、文件夹名称

方便快捷,支持正则表达式、无需安装功能齐全、支持定制无广告、无插件,放心使用。

免费下载 百度网盘
本站中所有的计算器的计算结果仅供参考,本站对此结果的准确性不承担任何责任,实际数额以银行/保险公司/国家相关机构确认的结果为准。
在线客服QQ:543690914,备案号: 苏ICP备15037649号-33。东海县白塔埠镇佳诚电脑经营部版权所有。