我有一个批处理文件,其中包含:
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 和其他平台上完美运行,但无法使用 C# 代码启动批处理文件Windows 2008 Server
和windows 8
. 命令窗口在启动后立即消失。但是当我手动单击并以管理员身份运行时,相同的批处理文件可以正常工作。任何人请给出任何解决方案。