无法获取IIS网站列表以允许用户选择在Inno脚本安装中使用的安装位置,请提供帮助
我目前正在尝试创建一个Inno脚本安装程序,该安装程序从用户的IIS安装中请求“网站”列表,以便用户可以从组合框列表中选择适当的网站,并且该列表可用于在正确的网站位置创建虚拟目录 我需要生成一个IIS网站列表,例如填充组合框的“默认网站” 到目前为止,我只能通过以下代码实现将虚拟目录安装到基于硬编码组合框选择的位置无法获取IIS网站列表以允许用户选择在Inno脚本安装中使用的安装位置,请提供帮助,iis,combobox,inno-setup,adsi,Iis,Combobox,Inno Setup,Adsi,我目前正在尝试创建一个Inno脚本安装程序,该安装程序从用户的IIS安装中请求“网站”列表,以便用户可以从组合框列表中选择适当的网站,并且该列表可用于在正确的网站位置创建虚拟目录 我需要生成一个IIS网站列表,例如填充组合框的“默认网站” 到目前为止,我只能通过以下代码实现将虚拟目录安装到基于硬编码组合框选择的位置 [Run] Filename: {sys}\iisvdir.vbs; Parameters: "/create ""{code:GetWebSite}"" MyApp ""{app}
[Run]
Filename: {sys}\iisvdir.vbs; Parameters: "/create ""{code:GetWebSite}"" MyApp ""{app}\Website"""; Flags: skipifdoesntexist waituntilterminated shellexec; StatusMsg: Creating IIS Virtual Directory
[Code]
var
WebsitePage: TWizardPage;
ComboBox: TNewComboBox;
procedure InitializeWizard;
begin
WebsitePage := CreateCustomPage(wpSelectComponents, 'Select which website you wish to install to',
'Which website should I install to?');
ComboBox := TNewComboBox.Create(WebsitePage);
ComboBox.Width := WebsitePage.SurfaceWidth;
ComboBox.Parent := WebsitePage.Surface;
ComboBox.Style := csDropDownList;
ComboBox.Items.Add('Default Web Site');
ComboBox.Items.Add('Website 1');
ComboBox.ItemIndex := 0;
end;
function GetWebSite(Param: String): String;
begin
{ Return the selected Website }
Result := ComboBox.Text;
end;
我现在需要做的就是动态设置用户在IIS中拥有的可用网站中的项目
谢谢你的帮助 我对你的问题有了进一步的了解,但我仍然没有解决它!我可以得到它出现在目录中的号码,但不能得到名字本身 这是我到目前为止得到的。如果你能更进一步,请告诉我你做了什么:) 抱歉,如果一个或两个组合框命名错误。我从我的来源复制了它,并试图把它和你的名字匹配起来。它基本上连接到IIS并列出Web服务器名称。出于某种原因,它们被称为身份证:( 我也不需要第二个功能(你的GetWeb站点) MSDN提到名称可以被覆盖以显示键,但没有详细说明,我疯狂地试图找出它可以被覆盖的地方,如果这是错误的话。
我对你的问题有了进一步的了解,但我仍然没有解决它!我可以得到它出现在目录中的数字,但不能得到名称本身 以下是我到目前为止所做的。如果你能更进一步,请让我知道你做了什么:) 抱歉,如果一个或两个组合框命名错误。我从我的来源复制了它,并试图把它和你的名字匹配起来。它基本上连接到IIS并列出Web服务器名称。出于某种原因,它们被称为身份证:( 我也不需要第二个功能(你的GetWeb站点) MSDN提到名称可以被覆盖以显示键,但没有详细说明,我疯狂地试图找出它可以被覆盖的地方,如果这是错误的话。 事实上,我昨天“解决”了这个问题,在这个问题上还没有发现任何其他东西,所以我想我们是先驱者;)。我开始了一长串你做的,但我找不到任何有用的文档,所以走了另一条路。虽然我的解决方案有效,但它非常混乱 基本上,我运行一个VB脚本,将网站列表输出到一个文本文件,然后将该文本文件读回Inno安装程序。下面是我当前的代码,非常粗糙,我计划稍后整理它并添加适当的错误处理 Website.vbs
OPTION EXPLICIT
DIM CRLF, TAB
DIM strServer
DIM objWebService
strServer = "localhost"
CRLF = CHR( 13 ) & CHR( 10 )
' WScript.Echo "Enumerating websites on " & strServer & CRLF
SET objWebService = GetObject( "IIS://" & strServer & "/W3SVC" )
EnumWebsites objWebService
SUB EnumWebsites( objWebService)
DIM objWebServer, objWebServerRoot, strBindings
Dim objFSO, objFolder, objShell, objTextFile, objFile
Dim strDirectory, strFile, strText
strFile = "website.txt"
' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strFile) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFile = objFSO.CreateTextFile(strFile)
' Wscript.Echo "Just created " & strDirectory & strFile
End If
set objFile = nothing
set objFolder = nothing
' ForAppending = 8 ForReading = 1, ForWriting = 2
Const ForAppending = 8
Set objTextFile = objFSO.OpenTextFile _
(strFile, ForAppending, True)
FOR EACH objWebServer IN objWebService
IF objWebserver.Class = "IIsWebServer" THEN
SET objWebServerRoot = GetObject(objWebServer.adspath & "/root")
' Writes strText every time you run this VBScript
objTextFile.WriteLine(objWebServer.ServerComment)
END IF
NEXT
objTextFile.Close
END SUB
Innosetup脚本
[Code]
var
WebsitePage: TWizardPage;
ComboBox: TNewComboBox;
WebSite: Variant;
WebServer: Variant;
WebRoot: Variant;
ErrorCode: Integer;
ResultCode: Integer;
Sites: AnsiString;
procedure InitializeWizard;
begin
ExtractTemporaryFile('Website.vbs');
if not ShellExec('', ExpandConstant('{tmp}\Website.vbs'), '', '', SW_SHOW, ewWaitUntilTerminated, ErrorCode) then
begin
MsgBox('Oh no!:' #13#13 'The file could not be executed. ' + SysErrorMessage(ResultCode) + '.', mbError, MB_OK);
end;
if LoadStringFromFile(ExpandConstant('{tmp}\website.txt'), Sites) then
begin
//MsgBox(Sites, mbInformation, MB_OK);
end else begin
Exit;
end;
WebsitePage := CreateCustomPage(DataDirPage.ID, 'Select which website you wish to install to',
'Which website should the application be install to?');
ComboBox := TNewComboBox.Create(WebsitePage);
ComboBox.Width := WebsitePage.SurfaceWidth;
ComboBox.Parent := WebsitePage.Surface;
ComboBox.Style := csDropDownList;
ComboBox.Items.Text := Sites;
ComboBox.ItemIndex := 0;
end;
事实上,我昨天“解决”了这个问题,在这个问题上还没有发现任何其他东西,所以我想我们是先驱;)。我开始了一长串你做的,但我找不到任何有用的文档,所以走了另一条路。虽然我的解决方案有效,但它非常混乱
基本上,我运行一个VB脚本,将网站列表输出到一个文本文件,然后将该文本文件读回Inno安装程序。下面是我当前的代码,非常粗糙,我计划稍后整理它并添加适当的错误处理
Website.vbs
OPTION EXPLICIT
DIM CRLF, TAB
DIM strServer
DIM objWebService
strServer = "localhost"
CRLF = CHR( 13 ) & CHR( 10 )
' WScript.Echo "Enumerating websites on " & strServer & CRLF
SET objWebService = GetObject( "IIS://" & strServer & "/W3SVC" )
EnumWebsites objWebService
SUB EnumWebsites( objWebService)
DIM objWebServer, objWebServerRoot, strBindings
Dim objFSO, objFolder, objShell, objTextFile, objFile
Dim strDirectory, strFile, strText
strFile = "website.txt"
' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strFile) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFile = objFSO.CreateTextFile(strFile)
' Wscript.Echo "Just created " & strDirectory & strFile
End If
set objFile = nothing
set objFolder = nothing
' ForAppending = 8 ForReading = 1, ForWriting = 2
Const ForAppending = 8
Set objTextFile = objFSO.OpenTextFile _
(strFile, ForAppending, True)
FOR EACH objWebServer IN objWebService
IF objWebserver.Class = "IIsWebServer" THEN
SET objWebServerRoot = GetObject(objWebServer.adspath & "/root")
' Writes strText every time you run this VBScript
objTextFile.WriteLine(objWebServer.ServerComment)
END IF
NEXT
objTextFile.Close
END SUB
Innosetup脚本
[Code]
var
WebsitePage: TWizardPage;
ComboBox: TNewComboBox;
WebSite: Variant;
WebServer: Variant;
WebRoot: Variant;
ErrorCode: Integer;
ResultCode: Integer;
Sites: AnsiString;
procedure InitializeWizard;
begin
ExtractTemporaryFile('Website.vbs');
if not ShellExec('', ExpandConstant('{tmp}\Website.vbs'), '', '', SW_SHOW, ewWaitUntilTerminated, ErrorCode) then
begin
MsgBox('Oh no!:' #13#13 'The file could not be executed. ' + SysErrorMessage(ResultCode) + '.', mbError, MB_OK);
end;
if LoadStringFromFile(ExpandConstant('{tmp}\website.txt'), Sites) then
begin
//MsgBox(Sites, mbInformation, MB_OK);
end else begin
Exit;
end;
WebsitePage := CreateCustomPage(DataDirPage.ID, 'Select which website you wish to install to',
'Which website should the application be install to?');
ComboBox := TNewComboBox.Create(WebsitePage);
ComboBox.Width := WebsitePage.SurfaceWidth;
ComboBox.Parent := WebsitePage.Surface;
ComboBox.Style := csDropDownList;
ComboBox.Items.Text := Sites;
ComboBox.ItemIndex := 0;
end;
好消息!!我发现了我们一直在寻找的隐藏的东西,你不需要一个单独的vb项目来修复它 这是我的密码:
[Code]
var
WebsitePage: TWizardPage;
ComboBox: TNewComboBox;
IIS, WebSite, WebServer: Variant;
IISServerIndex: Integer;
procedure InitializeWizard;
begin
WebsitePage := CreateCustomPage(wpSelectComponents, 'Select which website you wish to install to',
'Which website should I install to?');
ComboBox.Width := WebsitePage.SurfaceWidth;
ComboBox.Parent := WebsitePage.Surface;
ComboBox.Style := csDropDownList;
// ------------------------------------------------------------------------------
IIS := CreateOleObject('IISNamespace');
WebServer := IIS.GetObject('IIsWebService', IISServerName + '/w3svc');
IISServerIndex := 1;
try
while True do
begin
WebSite := WebServer.GetObject('IIsWebServer', IISServerIndex);
ComboBox.Items.Add(WebSite.ServerComment);
IISServerIndex := IISServerIndex + 1;
end;
except
end;
答案是将ComboBox.Items.Add行更改为.ServerComment,而不是.Name
享受:)
斯图好消息!!我发现了我们一直在寻找的隐藏的东西,你不需要一个单独的vb项目来修复它 这是我的密码:
[Code]
var
WebsitePage: TWizardPage;
ComboBox: TNewComboBox;
IIS, WebSite, WebServer: Variant;
IISServerIndex: Integer;
procedure InitializeWizard;
begin
WebsitePage := CreateCustomPage(wpSelectComponents, 'Select which website you wish to install to',
'Which website should I install to?');
ComboBox.Width := WebsitePage.SurfaceWidth;
ComboBox.Parent := WebsitePage.Surface;
ComboBox.Style := csDropDownList;
// ------------------------------------------------------------------------------
IIS := CreateOleObject('IISNamespace');
WebServer := IIS.GetObject('IIsWebService', IISServerName + '/w3svc');
IISServerIndex := 1;
try
while True do
begin
WebSite := WebServer.GetObject('IIsWebServer', IISServerIndex);
ComboBox.Items.Add(WebSite.ServerComment);
IISServerIndex := IISServerIndex + 1;
end;
except
end;
答案是将ComboBox.Items.Add行更改为.ServerComment,而不是.Name
享受:)
斯图您好,谢谢您的帮助,但不幸的是,这种方法并非在所有情况下都有效。在我的2003测试服务器上,每个网站都是使用非递增的ID号创建的,因此默认网站是1,但我的其他两个测试网站的ID是173839983和195896238。我的Test2008服务器以递增的方式创建ID,但是您可以通过从序列中间删除一两个网站来轻松打破ID序列。我不知道如何找到ID或FOR EACH循环方法,因此VBScript方法似乎仍然是迄今为止我找到的最好的方法。虽然不完整,但这仍然是一个合理的起点。但是,至少在Windows Server 2008 R2中,这取决于正在启用的IIS 6元数据库兼容性角色服务。我现在放弃这种方法,但我想我会为后代发帖。嗨,谢谢你,但不幸的是,这种方法并不适用于所有情况。在我的2003测试服务器上,每个网站都是使用非递增的ID号创建的,因此默认网站是1,但我的其他两个测试网站的ID是173839983和195896238。我的Test2008服务器以递增的方式创建ID,但是您可以通过从序列中间删除一两个网站来轻松打破ID序列。我不知道如何找到ID或FOR EACH循环方法,因此VBScript方法似乎仍然是迄今为止我找到的最好的方法。虽然不完整,但这仍然是一个合理的起点。但是,至少在Windows Server 2008 R2中,这取决于正在启用的IIS 6元数据库兼容性角色服务。我暂时放弃这种方法,但我想我会为后代发帖。