asp.net – Inno安装IIS安装和配置
|
我一直试图弄清楚如何使用Inno安装脚本安装和注册IIS,但到目前为止我还没有成功. 我需要创建一个带有.Net版本4的应用程序池和一个虚拟目录,获取机器的IP并继续使用此IP编辑网站的绑定. 到目前为止,我的安装中的所有工作都是检查IIS是否已安装. 如果有人曾经做过这样的事情,我真的很感激你能否分享你的剧本. 谢谢. 解决方法这是我使用Inno Setup处理IIS(Internet信息服务)的完整代码.它包含: >安装.NET Framework 4 它已经过以下Windows版本的测试: 一切都尽可能地被动完成,不会破坏任何现有的网站. 重要 这可能需要Inno-Setup的Unicode版本(我使用的是5.5.6(u)). [Setup] ArchitecturesInstallIn64BitMode=x64 要求助手 >一些常数 #ifdef UNICODE
#define AW "W"
#else
#define AW "A"
#endif
const
// See https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382.aspx
ERROR_SUCCESS = 0;
ERROR_INVALID_FUNCTION = 1;
ERROR_NOT_SUPPORTED = 50;
ERROR_NOT_FOUND = 1168;
ERROR_SUCCESS_REBOOT_REQUIRED = 3010;
function ExpandEnvironmentStrings(lpSrc: String; lpDst: String; nSize: DWORD): DWORD;
external 'ExpandEnvironmentStrings{#AW}@kernel32.dll stdcall';
function ExpandEnvVars(const Input: String): String;
var
Buf: String;
BufSize: DWORD;
begin
BufSize := ExpandEnvironmentStrings(Input,#0,0);
if BufSize > 0 then
begin
SetLength(Buf,BufSize);
if ExpandEnvironmentStrings(Input,Buf,BufSize) = 0 then
RaiseException(Format('Expanding env. strings failed. %s',[SysErrorMessage(DLLGetLastError)]));
#if AW == "A"
Result := Copy(Buf,1,BufSize - 2);
#else
Result := Copy(Buf,BufSize - 1);
#endif
end
else
RaiseException(Format('Expanding env. strings failed. %s',[SysErrorMessage(DLLGetLastError)]));
end;
// Exec with output stored in result. ResultString will only be altered if True is returned.
function ExecWithResult(const Filename,Params,WorkingDir: String; const ShowCmd: Integer; const Wait: TExecWait; var ResultCode: Integer; var ResultString: String): Boolean;
var
TempFilename: String;
TempAnsiStr: AnsiString;
Command: String;
begin
TempFilename := ExpandConstant('{tmp}~execwithresult.txt');
// Exec via cmd and redirect output to file. Must use special string-behavior to work.
Command := Format('"%s" /S /C ""%s" %s > "%s""',[ExpandConstant('{cmd}'),Filename,TempFilename]);
Result := Exec(ExpandConstant('{cmd}'),Command,WorkingDir,ShowCmd,Wait,ResultCode);
if not Result then
Exit;
LoadStringFromFile(TempFilename,TempAnsiStr); // Cannot fail
ResultString := String(TempAnsiStr);
DeleteFile(TempFilename);
// Remove new-line at the end
if (Length(ResultString) >= 2) and (ResultString[Length(ResultString) - 1] = #13) and (ResultString[Length(ResultString)] = #10) then
Delete(ResultString,Length(ResultString) - 1,2);
end;
function IIs7ExecAppCmd(Params: String; var ResultString: String; var ResultCode: Integer): Boolean;
var
AppCmdFilePath: String;
Command: String;
begin
AppCmdFilePath := ExpandConstant('{sys}inetsrvappcmd.exe');
Result := ExecWithResult(AppCmdFilePath,'',SW_HIDE,ewWaitUntilTerminated,ResultCode,ResultString);
end;
.NET 4安装 将为Win XP / 2003安装.NET 4.0.适用于Vista / 2008及更高版本的.NET 4.6. > .NET 4.0 Web安装程序“dotNetFx40_Full_setup.exe”=> https://www.microsoft.com/en-US/download/details.aspx?id=17851 – [Files]
Source: "dotNetFx40_Full_setup.exe"; DestDir: "{tmp}"; Flags: ignoreversion dontcopy
Source: "NDP46-KB3045560-Web.exe"; DestDir: "{tmp}"; Flags: ignoreversion dontcopy
Source: "wic_x64_enu.exe"; DestDir: "{tmp}"; Flags: ignoreversion dontcopy
Source: "wic_x86_enu.exe"; DestDir: "{tmp}"; Flags: ignoreversion dontcopy
由于我使用的是Web安装程序,因此在安装过程中可能需要连接互联网. // Checks if .NET 4 "Full" is installed
function IsDotNet4FullInstalled(): Boolean;
var
Success: Boolean;
Install: Cardinal;
begin
try
ExpandConstant('{dotnet40}'); // This will throw an exception if .NET 4 is not installed at all
Success := RegQueryDWordValue(HKLM,'SOFTWAREMicrosoftNET Framework SetupNDPv4Full','Install',Install); // Check for "Full" version
Result := Success and (Install = 1);
except
Result := False;
end;
end;
// Returns True if a restart is required.
function InstallDotNet4(): Boolean;
var
Version: TWindowsVersion;
ResultCode: Integer;
Success: Boolean;
begin
GetWindowsVersionEx(Version);
if (Version.Major <= 5) then // 4.0 for XP,2003
ExtractTemporaryFile('dotNetFx40_Full_setup.exe')
else // 4.6
ExtractTemporaryFile('NDP46-KB3045560-Web.exe');
if (Version.Major <= 5) then // XP,2003: Install .NET 4.0
begin
Success := Exec(ExpandConstant('{tmp}dotNetFx40_Full_setup.exe'),'/passive',ResultCode);
if Success and (ResultCode = 5100) then // Indicates that "Windows Imaging Component" is missing (probably 2003)
begin
if IsWin64 then
begin
ExtractTemporaryFile('wic_x64_enu.exe');
if not Exec(ExpandConstant('{tmp}wic_x64_enu.exe'),ResultCode) or (ResultCode <> ERROR_SUCCESS) then
RaiseException('Failed to install "Windows Imaging Component": ' + SysErrorMessage(ResultCode) + ' (' + IntToStr(ResultCode) + ')');
// Retry .NET
Success := Exec(ExpandConstant('{tmp}dotNetFx40_Full_setup.exe'),ResultCode);
end
else
begin
ExtractTemporaryFile('wic_x86_enu.exe');
if not Exec(ExpandConstant('{tmp}wic_x86_enu.exe'),ResultCode);
end;
end
end
else // Vista / 2008 or later: Install .NET 4.6
Success := Exec(ExpandConstant('{tmp}NDP46-KB3045560-Web.exe'),ResultCode);
// Check for errors
if not Success or ((ResultCode <> ERROR_SUCCESS) and (ResultCode <> ERROR_SUCCESS_REBOOT_REQUIRED)) then
RaiseException('Failed to install .NET: ' + SysErrorMessage(ResultCode) + ' (' + IntToStr(ResultCode) + ')');
Result := ResultCode = ERROR_SUCCESS_REBOOT_REQUIRED;
end;
IIS安装/卸载 使用ASP.NET安装IIS 4.将激活相同(默认)功能,就像通过GUI激活一样. 注意:对于Win XP / 2003,需要“Windows安装CD”. // Returns True if a restart is required. Throws exceptions.
function InstallIIs(): Boolean;
var
Version: TWindowsVersion;
Success: Boolean;
ResultCode: Integer;
IIS56IniFile: String;
begin
GetWindowsVersionEx(Version);
if (Version.Major <= 5) then // XP / 2003: Use "sysocmgr"
begin
IIS56IniFile := ExpandConstant('{tmp}~iis56.ini');
SaveStringToFile(IIS56IniFile,'[Components]' + #13#10 + 'iis_common = ON' + #13#10 + 'iis_www = ON' + #13#10 + 'iis_inetmgr = ON',False);
Success := Exec('sysocmgr',ExpandConstant('/i:"{win}infsysoc.inf" /u:"' + IIS56IniFile + '"'),SW_SHOW,ResultCode);
DeleteFile(IIS56IniFile);
end
else if (Version.Major = 6) and (Version.Minor = 0) then // Vista / 2008: Use "pkgmgr"
begin
Success := Exec('pkgmgr','/iu:' +
// Enables everything a fresh install would also (implicitly) enable.
// This is important in case IIS was already installed and some features manually disabled.
'WAS-WindowsActivationService;WAS-ProcessModel;WAS-NetFxEnvironment;WAS-ConfigurationAPI' +
';IIS-WebServerRole' +
';IIS-WebServerManagementTools;IIS-ManagementConsole' +
';IIS-WebServer' +
';IIS-ApplicationDevelopment;IIS-NetFxExtensibility;IIS-ASPNET;IIS-ISAPIExtensions;IIS-ISAPIFilter' +
';IIS-CommonHttpFeatures;IIS-HttpErrors;IIS-DefaultDocument;IIS-StaticContent;IIS-DirectoryBrowsing' +
';IIS-Performance;IIS-HttpCompressionStatic' +
';IIS-Security;IIS-RequestFiltering' +
';IIS-HealthAndDiagnostics;IIS-RequestMonitor;IIS-HttpLogging',ResultCode);
end
else if (Version.Major = 6) and (Version.Minor = 1) then // 7 / 2008 R2 / 2011: Use "Dism"
begin
Success := Exec('Dism','/Online /Enable-Feature' +
// Enables everything a fresh install would also (implicitly) enable.
// This is important in case IIS was already installed and some features manually disabled.
// "Parent fetaures" are NOT automatically enabled by "Dism".
' /FeatureName:WAS-WindowsActivationService /FeatureName:WAS-ProcessModel /FeatureName:WAS-NetFxEnvironment /FeatureName:WAS-ConfigurationAPI' +
' /FeatureName:IIS-WebServerRole' +
' /FeatureName:IIS-WebServerManagementTools /FeatureName:IIS-ManagementConsole' +
' /FeatureName:IIS-WebServer' +
' /FeatureName:IIS-ApplicationDevelopment /FeatureName:IIS-NetFxExtensibility /FeatureName:IIS-ASPNET /FeatureName:IIS-ISAPIExtensions /FeatureName:IIS-ISAPIFilter' +
' /FeatureName:IIS-CommonHttpFeatures /FeatureName:IIS-HttpErrors /FeatureName:IIS-DefaultDocument /FeatureName:IIS-StaticContent /FeatureName:IIS-DirectoryBrowsing' +
' /FeatureName:IIS-Performance /FeatureName:IIS-HttpCompressionStatic' +
' /FeatureName:IIS-Security /FeatureName:IIS-RequestFiltering' +
' /FeatureName:IIS-HealthAndDiagnostics /FeatureName:IIS-RequestMonitor /FeatureName:IIS-HttpLogging',ResultCode);
end
else // 8 / 2012 and later: Use "Dism"
begin
Success := Exec('Dism','/Online /Enable-Feature' +
// Enables everything a fresh install would also (implicitly) enable.
// This is important in case IIS was already installed and some features manually disabled.
' /FeatureName:WAS-WindowsActivationService /FeatureName:WAS-ProcessModel /FeatureName:WAS-NetFxEnvironment /FeatureName:WAS-ConfigurationAPI' +
' /FeatureName:IIS-ManagementConsole' +
' /FeatureName:IIS-HttpErrors /FeatureName:IIS-DefaultDocument /FeatureName:IIS-StaticContent /FeatureName:IIS-DirectoryBrowsing' +
' /FeatureName:IIS-ASPNET45' +
' /FeatureName:IIS-HttpCompressionStatic' +
' /FeatureName:IIS-RequestFiltering' +
' /FeatureName:IIS-HttpLogging' +
' /All',// Implicitly enables dependent features
'',ResultCode);
end;
if not Success or ((ResultCode <> ERROR_SUCCESS) and (ResultCode <> ERROR_SUCCESS_REBOOT_REQUIRED)) then
RaiseException('Cannot install IIS: ' + SysErrorMessage(ResultCode) + ' (' + IntToStr(ResultCode) + ')');
Result := ResultCode = ERROR_SUCCESS_REBOOT_REQUIRED;
// Register ASP.NET 4 with IIS. This is required since .NET 4 was probably installed before IIS.
// This will NOT change existing web-sites (which might be using other ASP.NET versions already)
if not Exec(ExpandConstant('{dotnet40}') + 'aspnet_regiis.exe','-iru -enable',ResultCode) or
(ResultCode <> ERROR_SUCCESS) then
RaiseException('Cannot register ASP.NET: ' + SysErrorMessage(ResultCode) + ' (' + IntToStr(ResultCode) + ')');
end;
// Returns True if a restart is required. Throws exceptions.
function UninstallIIs(): Boolean;
var
Version: TWindowsVersion;
Success: Boolean;
ResultCode: Integer;
IIS56IniFile: String;
begin
GetWindowsVersionEx(Version);
if (Version.Major <= 5) then // XP / 2003: Use "sysocmgr"
begin
IIS56IniFile := ExpandConstant('{tmp}~iis56.ini');
SaveStringToFile(IIS56IniFile,'[Components]' + #13#10 + 'iis_common = OFF' + #13#10 + 'iis_www = OFF' + #13#10 + 'iis_inetmgr = OFF',ResultCode);
DeleteFile(IIS56IniFile);
end
else if (Version.Major = 6) and (Version.Minor = 0) then // Vista / 2008: Use "pkgmgr"
Success := Exec('pkgmgr','/norestart /uu:IIS-WebServerRole',ResultCode)
else // 7 / 2008 R2 and later: Use "Dism"
Success := Exec('Dism','/NoRestart /Online /Disable-Feature /FeatureName:IIS-WebServerRole',ResultCode);
if not Success or ((ResultCode <> ERROR_SUCCESS) and (ResultCode <> ERROR_SUCCESS_REBOOT_REQUIRED)) then
RaiseException('Cannot uninstall IIS: ' + SysErrorMessage(ResultCode) + ' (' + IntToStr(ResultCode) + ')');
Result := ResultCode = ERROR_SUCCESS_REBOOT_REQUIRED;
end;
网站/应用程序注册和删除 创建虚拟目录和ASP.NET 4应用程序池. 注意:IIsServerNumber是实际的网站,通常默认为1(=>“默认网站”). (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- 为什么NuPack生成的NinjectMVC3.cs无法编译? (或者ASP.NET
- asp.net – 如何在转发器中每行显示x个项目?
- 我可以使用MiniProfiler来检测ASP.NET MVC WebApi网站吗?
- asp.net-mvc – ASP.NET MVC泛型基础视图类
- asp.net-mvc-3 – 如何在Entity Framework中更新实体的导航
- asp.net – 身份cookie在一段时间后会丢失自定义索赔信息
- asp.net – 如何在页面加载中以编程方式向页面添加控件?
- ASP.Net文本框从右到左
- ASP.NET隐藏字段与不可见的文本框
- ASP.NET WebSite发布与复制?
- asp.net – MVC3 – 向控制器添加一个文件夹?
- asp.net-mvc – 在ASP.NET MVC Preview 4中使用路
- asp.net-web-api – webapi批处理和委托处理程序
- asp.net-mvc-3 – DropDownListFor Unobtrusive
- 验证 – ASP.NET MVC 4避免生成datetime的data-v
- asp.net-web-api – 标题中的API密钥与swashbuck
- 非锁定进程中的ASP.NET会话状态存储
- asp.net – 诸如Eval(),XPath()和Bind()的数据绑
- asp.net-mvc – 避免“类或CssClass值未定义”AS
- asp.net-mvc – 在asp.net mvc中选择列表用法
