在cmd命令工具下,使用管理员权限可用

控制某一个网站

  • 查看命令:C:\Windows\System32\inetsrv\appcmd.exe /?
  • 开启某网站:C:\Windows\System32\inetsrv\appcmd.exe start site “XXXX”
  • 关闭某网站:C:\Windows\System32\inetsrv\appcmd.exe stop site “XXXX”
  • 停止“应用程序池”:C:\Windows\System32\inetsrv\appcmd.exe stop apppool /apppool.name:xxxx
  • 启动“应用程序池”:C:\Windows\System32\inetsrv\appcmd.exe start apppool /apppool.name:xxxx

iis命令

  • 启动IIS:iisreset /START
  • 停止IIS:iisreset /STOP
  • 重启IIS:iisreset /RESTART
  • 重启电脑:iisreset /REBOOT
  • 如果停止IIS失败重启电脑:iisreset /rebootonerror
  • 不用强迫IIS停止:iisreset /NOFORCE
  • 在X秒后,IIS被强制停止,除非 /NOFORCE 参数给出.:iisreset /TIMEOUT:X
  • 显示所有Internet服务状态:iisreset /status
  • 本地系统上启用(禁用)Internet服务的重新启动:iisreset /enable或disable
  • 若无法停止Internet服务,将不会强制终止Internet服务:iisreset /noforce

如果想自动运行某条命令可以将命令写入bat,然后使用计划服务或者定时任务等运行即可

使用dll

Microsoft中提供了管理IIS7及以上版本一个非常强大的API - Microsoft.Web.Administration.dll,利用该API可以让我们很方便的以编程的方式管理和设定IIS的各项配置信息了。
Microsoft.Web.Administration.dll位于IIS目录下(%WinDir%\System32\InetSrv)下,在项目中添加引用后就可以使用这些API了。

参考资料:
https://msdn.microsoft.com/en-us/library/microsoft.web.administration(v=vs.90).aspx

https://docs.microsoft.com/en-us/dotnet/api/microsoft.web.administration?redirectedfrom=MSDN&view=iis-dotnet

下面通过代码进行web发布:

1、添加 Microsoft.Web.Administration.dll 引用
2、引用命名空间 using Microsoft.Web.Administration;

/// <summary>/// 使用代码进行web发布/// </summary>/// <param name="webName">web应用程序名称</param>/// <param name="port">web应用程序端口</param>/// <returns></returns>private bool PublishWeb(string webName, int port){try{ServerManager iismanager = new ServerManager();//判断应用程序池是否存在if (iismanager.ApplicationPools[webName] != null){iismanager.ApplicationPools.Remove(iismanager.ApplicationPools[webName]);}//判断web应用程序是否存在if (iismanager.Sites[webName] != null){iismanager.Sites.Remove(iismanager.Sites[webName]);}//建立web应用程序(第二个参数为安装文件的地址)iismanager.Sites.Add(webName, "c:\\webFilePath", port);//添加web应用程序池ApplicationPool pool = iismanager.ApplicationPools.Add(webName);//设置web应用程序池的Framework版本(注意版本号大小写问题)pool.ManagedRuntimeVersion = "v4.0";//设置是否启用32为应用程序pool.SetAttributeValue("enable32BitAppOnWin64", true);//设置web网站的应用程序池iismanager.Sites[webName].Applications[0].ApplicationPoolName = webName;//提交更改iismanager.CommitChanges();return true;}catch (Exception ex){throw (ex);}}
Microsoft.Web.Administration.ServerManager sm = new Microsoft.Web.Administration.ServerManager();System.Console.WriteLine("应用程序池默认设置:");System.Console.WriteLine("\t常规:");System.Console.WriteLine("\t\t.NET Framework 版本:{0}", sm.ApplicationPoolDefaults.ManagedRuntimeVersion);System.Console.WriteLine("\t\t队列长度:{0}", sm.ApplicationPoolDefaults.QueueLength);System.Console.WriteLine("\t\t托管管道模式:{0}", sm.ApplicationPoolDefaults.ManagedPipelineMode.ToString());System.Console.WriteLine("\t\t自动启动:{0}", sm.ApplicationPoolDefaults.AutoStart);System.Console.WriteLine("\tCPU:");System.Console.WriteLine("\t\t处理器关联掩码:{0}", sm.ApplicationPoolDefaults.Cpu.SmpProcessorAffinityMask);System.Console.WriteLine("\t\t限制:{0}", sm.ApplicationPoolDefaults.Cpu.Limit);System.Console.WriteLine("\t\t限制操作:{0}", sm.ApplicationPoolDefaults.Cpu.Action.ToString());System.Console.WriteLine("\t\t限制间隔(分钟):{0}", sm.ApplicationPoolDefaults.Cpu.ResetInterval.TotalMinutes);System.Console.WriteLine("\t\t已启用处理器关联:{0}", sm.ApplicationPoolDefaults.Cpu.SmpAffinitized);System.Console.WriteLine("\t回收:");System.Console.WriteLine("\t\t发生配置更改时禁止回收:{0}", sm.ApplicationPoolDefaults.Recycling.DisallowRotationOnConfigChange);System.Console.WriteLine("\t\t固定时间间隔(分钟):{0}", sm.ApplicationPoolDefaults.Recycling.PeriodicRestart.Time.TotalMinutes);System.Console.WriteLine("\t\t禁用重叠回收:{0}", sm.ApplicationPoolDefaults.Recycling.DisallowOverlappingRotation);System.Console.WriteLine("\t\t请求限制:{0}", sm.ApplicationPoolDefaults.Recycling.PeriodicRestart.Requests);System.Console.WriteLine("\t\t虚拟内存限制(KB):{0}", sm.ApplicationPoolDefaults.Recycling.PeriodicRestart.Memory);System.Console.WriteLine("\t\t专用内存限制(KB):{0}", sm.ApplicationPoolDefaults.Recycling.PeriodicRestart.PrivateMemory);System.Console.WriteLine("\t\t特定时间:{0}", sm.ApplicationPoolDefaults.Recycling.PeriodicRestart.Schedule.ToString());System.Console.WriteLine("\t\t生成回收事件日志条目:{0}", sm.ApplicationPoolDefaults.Recycling.LogEventOnRecycle.ToString());System.Console.WriteLine("\t进程孤立:");System.Console.WriteLine("\t\t可执行文件:{0}", sm.ApplicationPoolDefaults.Failure.OrphanActionExe);System.Console.WriteLine("\t\t可执行文件参数:{0}", sm.ApplicationPoolDefaults.Failure.OrphanActionParams);System.Console.WriteLine("\t\t已启用:{0}", sm.ApplicationPoolDefaults.Failure.OrphanWorkerProcess);System.Console.WriteLine("\t进程模型:");System.Console.WriteLine("\t\tPing 间隔(秒):{0}", sm.ApplicationPoolDefaults.ProcessModel.PingInterval.TotalSeconds);System.Console.WriteLine("\t\tPing 最大响应时间(秒):{0}", sm.ApplicationPoolDefaults.ProcessModel.PingResponseTime.TotalSeconds);System.Console.WriteLine("\t\t标识:{0}", sm.ApplicationPoolDefaults.ProcessModel.IdentityType);System.Console.WriteLine("\t\t用户名:{0}", sm.ApplicationPoolDefaults.ProcessModel.UserName);System.Console.WriteLine("\t\t密码:{0}", sm.ApplicationPoolDefaults.ProcessModel.Password);System.Console.WriteLine("\t\t关闭时间限制(秒):{0}", sm.ApplicationPoolDefaults.ProcessModel.ShutdownTimeLimit.TotalSeconds);System.Console.WriteLine("\t\t加载用户配置文件:{0}", sm.ApplicationPoolDefaults.ProcessModel.LoadUserProfile);System.Console.WriteLine("\t\t启动时间限制(秒):{0}", sm.ApplicationPoolDefaults.ProcessModel.StartupTimeLimit.TotalSeconds);System.Console.WriteLine("\t\t允许 Ping:{0}", sm.ApplicationPoolDefaults.ProcessModel.PingingEnabled);System.Console.WriteLine("\t\t闲置超时(分钟):{0}", sm.ApplicationPoolDefaults.ProcessModel.IdleTimeout.TotalMinutes);System.Console.WriteLine("\t\t最大工作进程数:{0}", sm.ApplicationPoolDefaults.ProcessModel.MaxProcesses);System.Console.WriteLine("\t快速故障防护:");System.Console.WriteLine("\t\t“服务不可用”响应类型:{0}", sm.ApplicationPoolDefaults.Failure.LoadBalancerCapabilities.ToString());System.Console.WriteLine("\t\t故障间隔(分钟):{0}", sm.ApplicationPoolDefaults.Failure.RapidFailProtectionInterval.TotalMinutes);System.Console.WriteLine("\t\t关闭可执行文件:{0}", sm.ApplicationPoolDefaults.Failure.AutoShutdownExe);System.Console.WriteLine("\t\t关闭可执行文件参数:{0}", sm.ApplicationPoolDefaults.Failure.AutoShutdownParams);System.Console.WriteLine("\t\t已启用:{0}", sm.ApplicationPoolDefaults.Failure.RapidFailProtection);System.Console.WriteLine("\t\t最大故障数:{0}", sm.ApplicationPoolDefaults.Failure.RapidFailProtectionMaxCrashes);System.Console.WriteLine("\t\t允许32位应用程序运行在64位 Windows 上:{0}", sm.ApplicationPoolDefaults.Enable32BitAppOnWin64);System.Console.WriteLine();System.Console.WriteLine("网站默认设置:");System.Console.WriteLine("\t常规:");System.Console.WriteLine("\t\t物理路径凭据:UserName={0}, Password={1}", sm.VirtualDirectoryDefaults.UserName, sm.VirtualDirectoryDefaults.Password);System.Console.WriteLine("\t\t物理路径凭据登录类型:{0}", sm.VirtualDirectoryDefaults.LogonMethod.ToString());System.Console.WriteLine("\t\t应用程序池:{0}", sm.ApplicationDefaults.ApplicationPoolName);System.Console.WriteLine("\t\t自动启动:{0}", sm.SiteDefaults.ServerAutoStart);System.Console.WriteLine("\t行为:");System.Console.WriteLine("\t\t连接限制:");System.Console.WriteLine("\t\t\t连接超时(秒):{0}", sm.SiteDefaults.Limits.ConnectionTimeout.TotalSeconds);System.Console.WriteLine("\t\t\t最大并发连接数:{0}", sm.SiteDefaults.Limits.MaxConnections);System.Console.WriteLine("\t\t\t最大带宽(字节/秒):{0}", sm.SiteDefaults.Limits.MaxBandwidth);System.Console.WriteLine("\t\t失败请求跟踪:");System.Console.WriteLine("\t\t\t跟踪文件的最大数量:{0}", sm.SiteDefaults.TraceFailedRequestsLogging.MaxLogFiles);System.Console.WriteLine("\t\t\t目录:{0}", sm.SiteDefaults.TraceFailedRequestsLogging.Directory);System.Console.WriteLine("\t\t\t已启用:{0}", sm.SiteDefaults.TraceFailedRequestsLogging.Enabled);System.Console.WriteLine("\t\t已启用的协议:{0}", sm.ApplicationDefaults.EnabledProtocols);foreach (var s in sm.Sites)//遍历网站{System.Console.WriteLine();System.Console.WriteLine("模式名:{0}", s.Schema.Name);System.Console.WriteLine("编号:{0}", s.Id);System.Console.WriteLine("网站名称:{0}", s.Name);System.Console.WriteLine("物理路径:{0}", s.Applications["/"].VirtualDirectories["/"].PhysicalPath);System.Console.WriteLine("物理路径凭据:{0}", s.Methods.ToString());System.Console.WriteLine("应用程序池:{0}", s.Applications["/"].ApplicationPoolName);System.Console.WriteLine("已启用的协议:{0}", s.Applications["/"].EnabledProtocols);System.Console.WriteLine("自动启动:{0}", s.ServerAutoStart);System.Console.WriteLine("运行状态:{0}", s.State.ToString());System.Console.WriteLine("网站绑定:");foreach (var tmp in s.Bindings){System.Console.WriteLine("\t类型:{0}", tmp.Protocol);System.Console.WriteLine("\tIP 地址:{0}", tmp.EndPoint.Address.ToString());System.Console.WriteLine("\t端口:{0}", tmp.EndPoint.Port.ToString());System.Console.WriteLine("\t主机名:{0}", tmp.Host);//System.Console.WriteLine(tmp.BindingInformation);//System.Console.WriteLine(tmp.CertificateStoreName);//System.Console.WriteLine(tmp.IsIPPortHostBinding);//System.Console.WriteLine(tmp.IsLocallyStored);//System.Console.WriteLine(tmp.UseDsMapper);}System.Console.WriteLine("连接限制:");System.Console.WriteLine("\t连接超时(秒):{0}", s.Limits.ConnectionTimeout.TotalSeconds);System.Console.WriteLine("\t最大并发连接数:{0}", s.Limits.MaxConnections);System.Console.WriteLine("\t最大带宽(字节/秒):{0}", s.Limits.MaxBandwidth);System.Console.WriteLine("失败请求跟踪:");System.Console.WriteLine("\t跟踪文件的最大数量:{0}", s.TraceFailedRequestsLogging.MaxLogFiles);System.Console.WriteLine("\t目录:{0}", s.TraceFailedRequestsLogging.Directory);System.Console.WriteLine("\t已启用:{0}", s.TraceFailedRequestsLogging.Enabled);System.Console.WriteLine("日志:");//System.Console.WriteLine("\t启用日志服务:{0}", s.LogFile.Enabled);System.Console.WriteLine("\t格式:{0}", s.LogFile.LogFormat.ToString());System.Console.WriteLine("\t目录:{0}", s.LogFile.Directory);System.Console.WriteLine("\t文件包含字段:{0}", s.LogFile.LogExtFileFlags.ToString());System.Console.WriteLine("\t计划:{0}", s.LogFile.Period.ToString());System.Console.WriteLine("\t最大文件大小(字节):{0}", s.LogFile.TruncateSize);System.Console.WriteLine("\t使用本地时间进行文件命名和滚动更新:{0}", s.LogFile.LocalTimeRollover);System.Console.WriteLine("----应用程序的默认应用程序池:{0}", s.ApplicationDefaults.ApplicationPoolName);System.Console.WriteLine("----应用程序的默认已启用的协议:{0}", s.ApplicationDefaults.EnabledProtocols);//System.Console.WriteLine("----应用程序的默认物理路径凭据:{0}", s.ApplicationDefaults.Methods.ToString());//System.Console.WriteLine("----虚拟目录的默认物理路径凭据:{0}", s.VirtualDirectoryDefaults.Methods.ToString());System.Console.WriteLine("----虚拟目录的默认物理路径凭据登录类型:{0}", s.VirtualDirectoryDefaults.LogonMethod.ToString());System.Console.WriteLine("----虚拟目录的默认用户名:{0}", s.VirtualDirectoryDefaults.UserName);System.Console.WriteLine("----虚拟目录的默认用户密码:{0}", s.VirtualDirectoryDefaults.Password);System.Console.WriteLine("应用程序 列表:");foreach (var tmp in s.Applications){if (tmp.Path != "/"){System.Console.WriteLine("\t模式名:{0}", tmp.Schema.Name);System.Console.WriteLine("\t虚拟路径:{0}", tmp.Path);System.Console.WriteLine("\t物理路径:{0}", tmp.VirtualDirectories["/"].PhysicalPath);//System.Console.WriteLine("\t物理路径凭据:{0}", tmp.Methods.ToString());System.Console.WriteLine("\t应用程序池:{0}", tmp.ApplicationPoolName);System.Console.WriteLine("\t已启用的协议:{0}", tmp.EnabledProtocols);}System.Console.WriteLine("\t虚拟目录 列表:");foreach (var tmp2 in tmp.VirtualDirectories){if (tmp2.Path != "/"){System.Console.WriteLine("\t\t模式名:{0}", tmp2.Schema.Name);System.Console.WriteLine("\t\t虚拟路径:{0}", tmp2.Path);System.Console.WriteLine("\t\t物理路径:{0}", tmp2.PhysicalPath);//System.Console.WriteLine("\t\t物理路径凭据:{0}", tmp2.Methods.ToString());System.Console.WriteLine("\t\t物理路径凭据登录类型:{0}", tmp2.LogonMethod.ToString());}}}}

在对web应用程序池属性进行设置时,可以参考IIS管理器中对应的属性,点击每个属性在说明框中都会有属性的名称,通过该名称可以通过代码设置对应的值。

iis命令(网站自动开启关闭)相关推荐

  1. php夜间,php实现自动开启/关闭夜间模式

    说明 纯属没事写着玩的,别上纲上线.判断日出日落都是按照北京时间来的,不会按照ip地址精确到省份.我是写代码的,不是气象台的! 实现 首先,想要自动开启/关闭夜间模式我们需要知道现在的太阳的状态(日出 ...

  2. 优雅的启动nginx。。。bat命令。一键开启关闭

    启动nginx 点击启动 点击关闭 问题 吐槽 启动nginx 最开始的时候我是一个小小白,启动关闭nginx的时候就是双击启动,以及在任务管理器关闭...十分的麻烦. 于是 我看了看隔壁王哥怎么做的 ...

  3. IOS快捷指令-工作日午休勿扰自动开启/关闭

    一.需求来源: 为了中午午休时不被应用通知打扰 二.使用iPhone的快捷指令配合 自动化 实现中午12点–14点 自动开启勿扰模式,屏蔽App通知. 但保留来电/短信 三.使用方法: 直接使用Saf ...

  4. linux ubuntu 关闭防火墙命令,Linux下开启/关闭防火墙命令

    iptables用于过滤数据包,属于网络层防火墙. firewall能够允许哪些服务可用,那些端口可用.... 属于更高一层的防火墙. firewall的底层是使用iptables进行数据过滤,建立在 ...

  5. IIS服务器网站自动创建并部署

    color 6 echo "正在解压服务端资源..." %RAR_ROOT%\rar.exe x -y Unicode_HY.rar * echo "服务端资源解压完成& ...

  6. iis服务器 关闭自动启动,设置IIS服务器定时自动重启的方法

    最近,有一朋友的IIS服务器老是出现问题,运行一段时间下来就会出现访问服务器上的网站时提示数据库连接出错,然后重启IIS后网站又能正常访问了,实在找不出是什么原因导致了这个问题.不过最终我想到了一个笨 ...

  7. linux 关闭自动升级,开启关闭Centos的自动更新(转)

    开启关闭Centos的自动更新 关闭Centos的自动更新,操作记录如下: [[email protected] alpha]# chkconfig –list yum-updatesd yum-up ...

  8. Linux查看防火墙状态及开启关闭命令

    Linux查看防火墙状态及开启关闭命令 CentOS7 使用firewalld开启关闭防火墙与端口 systemctl 配置firewalld-cmd iptables CentOS6 Ubuntu ...

  9. 设置开机时自动开启和关闭的软件

    我们有时候开机的时候,系统会自动打开一些软件,导致开机速度慢,有些软件是我们不想打开的. 解决的方法是安装电脑管家,然后在开机加速里头选择,它会有一个列表,里头显示了哪些软件是开机的时候自动开启的,如 ...

最新文章

  1. Ubuntu18.04:错误整理
  2. LeetCode实战:只出现一次的数字
  3. P2024 食物链 (补集)
  4. [翻译] TWRPickerSlider
  5. python创建数字列表_Python创建数字列表
  6. cake-build -.Net Core 跨平台构建自动化系统。
  7. 论文浅尝 | 一种基于递归超图的知识图谱问答方法
  8. 【SQL Server配置管理器】提示:无法连接到 WMI 提供程序。您没有权限或者该服务器无法访问...
  9. openstack 开发_2016年OpenStack开发板工作清单
  10. common java socket,JAVA I/O(四)网络Socket和ServerSocket
  11. 企业网站+Axure企业官网通用模板+公司官网通用模板+web端高保真原型+门户官网+物流企业+门户网站+服务中心+产品中心+新闻中心+帮助中心+企业官网+公司官网+公司网站+登录注册+高保真交互
  12. 圆弧裁剪算法c++_箍筋算法之争:按外皮长度计算与按中心线长度计算究竟相差多少?...
  13. 理解分布式和集群的区别
  14. 怎么读取二代身份证UUID----在STM32+CLRC663平台试验成功
  15. arcgispython空间插值_[转载]ARCGIS中几种空间插值简单比较
  16. 通过CSS在金钱单位前加上货币符号
  17. 从我开发的深度学习框架看深度学习这几年:TensorFlow, PaddlePaddle(飞桨), 无量...
  18. java毕业设计视频点播系统Mybatis+系统+数据库+调试部署
  19. Message中obtain()与recycle()
  20. 2017年4月历史文章汇总

热门文章

  1. 什么是开源表单设计器?
  2. 第2期-通过去哪儿爬取机票价格
  3. 批处理文件(bat文件)注册dll
  4. 如何查看dll文件是32位还是64位
  5. VMware Horizon 8 2111 部署系列(五)配置事件数据库
  6. 自适应均衡matlab仿真,对比RLS,LMS以及NLMS的均衡前后星座图效果,调制采用4QAM,16QAM,64QAM
  7. 前端在线预览word,excel,pdf
  8. 对实例化需求方法的整理与思考
  9. 集成电路中电流镜的分析与布局设计
  10. eps倾斜摄影矢量化采集毕业设计_eps倾斜摄影矢量化dlg采集#知识参考