pcbabu
pcbabu

Reputation: 2329

How to install IIS in windows 2008 windows by C#

I got an batch file that contains:

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

Which will download IIS from internet and will install in local machine. I used C# code to call this installiis.bat. The code is

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();

This code works perfectly in win7 and other platform but the batch file can not be started using C# code in Windows 2008 Server and windows 8. The command window immediately disappears after starting. But the same batch file works fine when I manually click and run as administrator. Anyone please give any solution.

Upvotes: 2

Views: 1327

Answers (1)

Oscar
Oscar

Reputation: 13990

I think that you will have to add an Application Manifest to your program to request elevated rights for your application.

http://msdn.microsoft.com/en-us/library/windows/desktop/bb756929.aspx

Upvotes: 2

Related Questions