【发布时间】:2013-04-29 13:52:56
【问题描述】:
我得到一个批处理文件,其中包含:
start /w dism /online /enable-feature /featurename:IIS-WebServerRole
start /w dism /online /enable-feature /featurename:IIS-WebServer
start /w dism /online /enable-feature /featurename:IIS-IIS6ManagementCompatibility
start /w dism /online /enable-feature /featurename:IIS-Metabase
start /w dism /online /enable-feature /featurename:IIS-ManagementService
start /w dism /online /enable-feature /featurename:IIS-HttpRedirect
start /w dism /online /enable-feature /featurename:IIS-RequestMonitor
start /w dism /online /enable-feature /featurename:IIS-BasicAuthentication
start /w dism /online /enable-feature /featurename:IIS-WindowsAuthentication
start /w dism /online /enable-feature /featurename:IIS-ISAPIExtensions
start /w dism /online /enable-feature /featurename:IIS-ASP
start /w dism /online /enable-feature /featurename:IIS-ISAPIFilter
rem WIN 8 Only
start /w dism /online /enable-feature /featurename:NetFx3
start /w dism /online /enable-feature /featurename:NetFx4Extended-ASPNET45
start /w dism /online /enable-feature /featurename:IIS-NetFxExtensibility
start /w dism /online /enable-feature /featurename:IIS-ASPNET
start /w dism /online /enable-feature /featurename:IIS-ServerSideIncludes
rem WIN 8 Only
start /w dism /online /enable-feature /featurename:IIS-NetFxExtensibility45
start /w dism /online /enable-feature /featurename:IIS-ASPNET45
echo IIS installation complete
将从 Internet 下载 IIS 并安装在本地计算机上。我使用 C# 代码将其称为installiis.bat。代码是
batchCommand = installiis.bat;
procStartInfo = new ProcessStartInfo();
procStartInfo.WorkingDirectory = targetDir;
procStartInfo.FileName = batchCommand;
procStartInfo.Arguments = argument;//this is argument
procStartInfo.CreateNoWindow = true;
procStartInfo.UseShellExecute = true;
procStartInfo.Verb = "runas";
proc.StartInfo = procStartInfo;
proc.Start();
proc.WaitForExit();
此代码在win7和其他平台下完美运行,但无法使用Windows 2008 Server和windows 8中的C#代码启动批处理文件。命令窗口在启动后立即消失。但是当我手动单击并以管理员身份运行时,相同的批处理文件可以正常工作。请任何人提供任何解决方案。
【问题讨论】:
-
您是否尝试过使用管理权限执行您的 C# 应用程序?
-
感谢@gustavodidomenico。这行得通。
标签: c# windows iis-7 batch-file