編集:以下のコードを更新して、Robの答えを受けて動作するようにしました。インストール時にComboBoxにWiXを挿入するにはどうすればよいですか?
私はこれを行う方法を表示するページのカップル(http://www.cmcrossroads.com/content/view/13160/120/、http://www.mail-archive.com/[email protected]/msg05103.html)を発見し、WAIのソースコード(http://wai.codeplex.com/)を通じて見えたが、私はそれが私のインストーラで仕事を得るように見えることはできませんしました私が何を試みても。誰かが私が間違っていることに気づくことができれば、とても感謝しています。対話のための私のWiXフラグメントは、次のようになります。
<UI>
<Dialog>
...snip...
<Control Id="WebsiteName" Type="ComboBox" ComboList="yes" Sorted="yes" Property="IIS_WEBSITENAME" X="20" Y="73" Width="150" Height="17"/>
...snip...
<!-- We want our custom action to fill in the WebsiteName ComboBox above
however, if no ComboBox entries exist at compile time then the
ComboBox table is not created in the MSI and we can't add to it in
the custom action. So we have this hidden dummy list box to force
the table to appear. -->
<Control Id="DummyComboBox" Hidden="yes" Type="ComboBox" Sorted="yes" ComboList="yes" Property="DUMMYPROPERTY" X="65" Y="60" Width="150" Height="18">
<ComboBox Property="DUMMYPROPERTY">
<ListItem Text="Dummy" Value="Dummy"/>
</ComboBox>
</Control>
</Dialog>
</UI>
<Property Id="DUMMYPROPERTY">Dummy</Property>
<Property Id="IIS_WEBSITENAME"/>
<CustomAction Id="FillWebsiteNameList" BinaryKey="WiXCustomAction.dll" DllEntry="FillWebsiteNameList" Execute="immediate" />
<InstallUISequence>
<Custom Action="FillWebsiteNameList" After="CostFinalize"/>
</InstallUISequence>
マイカスタムアクションコードは次のとおりです。
[CustomAction]
public static ActionResult FillWebsiteNameList(Session xiSession)
{
xiSession.Log("Begin FillWebsiteNameList");
xiSession.Log("Opening view");
View lView = xiSession.Database.OpenView("SELECT * FROM ComboBox");
lView.Execute();
xiSession.Log("Creating directory entry");
DirectoryEntry lIis = new DirectoryEntry("IIS://localhost/w3svc");
xiSession.Log("Checking each child entry");
int lIndex = 1;
foreach (DirectoryEntry lEntry in lIis.Children)
{
if (lEntry.SchemaClassName == "IIsWebServer")
{
xiSession.Log("Found web server entry: " + lEntry.Name);
string lWebsiteName = (string)lEntry.Properties["ServerComment"].Value;
xiSession.Log("Website name: " + lWebsiteName);
xiSession.Log("Creating record");
Record lRecord = xiSession.Database.CreateRecord(4);
xiSession.Log("Setting record details");
lRecord.SetString(1, "IIS_WEBSITENAME");
lRecord.SetInteger(2, lIndex);
lRecord.SetString(3, lEntry.Name); // Use lWebsiteName only if you want to look up the site by name.
lRecord.SetString(4, lWebsiteName);
xiSession.Log("Adding record");
lView.Modify(ViewModifyMode.InsertTemporary, lRecord);
++lIndex;
}
}
xiSession.Log("Closing view");
lView.Close();
xiSession.Log("Return success");
return ActionResult.Success;
}
二つの問題がありました:
1)走行時に失敗した上記のコード「実行中に関数が失敗しました。」データベース:テーブルの更新に失敗しました。これは、索引付けの問題により、コードが文字列をint列に書き込んで書き込むためです。
2)私は
lRecord.SetString(2, lEntry.Name);
にライン
lRecord.SetString(2, lWebsiteName);
を変更する場合は、トレースでアクションを見ては成功したように見えますが、インストーラの実行時にコンボボックスから選択することはございません。
ハードコードされた値を持つようにコンボボックスを変更した場合、lWebsiteNameに相当するものをハードコードしても、すべて正常に動作します。
ので、インストーラが管理者として実行する必要がありますか?またはどのようにWebサイトのリストを取得しようとすると拒否されたアクセスを避けるのですか? –
これは管理者として実行する必要があります。その問題をお楽しみください。 – jcmcbeth