我正在使用wix创建一个安装程序。我需要在安装过程中安装一个服务作为用户帐户。但是,在安装服务之前,我如何验证用户和密码是否有效,并且还有足够的特权来安装服务。有办法吗?
以下代码在wix中帮助我安装服务。
<ServiceInstall Id="AServiceInstall" DisplayName="myservice" Name="myservice" ErrorControl="normal" Start="auto" Vital="yes" Type="ownProcess" Account="[ACCOUNT]" Password="[PASSWORD]">
<ServiceDependency Id="x"></ServiceDependency>
</ServiceInstall>
答案 0 :(得分:2)
为了验证复杂的用户输入,我通常必须创建一个自定义操作来执行此操作。
这是一个示例对话框,用于验证Web服务的URL并确保它可以访问:
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<CustomAction Id="ValidateProxyService" BinaryKey="XXX.CommServer.CustomActions.dll" DllEntry="ValidateProxyService" Return="check" />
<UI>
<Dialog Id="XxxInquiryServiceDlg" Width="370" Height="270" Title="CommService Setup">
<Control Id="BannerBitmap" Type="Bitmap" X="0" Y="0" Width="370" Height="44" TabSkip="no" Text="!(loc.InstallDirDlgBannerBitmap)" />
<Control Id="BannerLine" Type="Line" X="0" Y="44" Width="370" Height="0" />
<Control Id="BottomLine" Type="Line" X="0" Y="234" Width="370" Height="2" />
<Control Id="Description" Type="Text" X="25" Y="23" Width="280" Height="15" Transparent="yes" NoPrefix="yes" Text="Configure the settings for the xxx." />
<Control Id="Title" Type="Text" X="15" Y="6" Width="210" Height="15" Transparent="yes" NoPrefix="yes" Text="{\WixUI_Font_Title}Configure xxx" />
<Control Type="Text" Id="ProxyServiceLabel" Width="95" Height="10" X="11" Y="60" Text="XXX Proxy Service URL:" />
<Control Type="Edit" Id="ProxyServiceTextBox" Width="244" Height="15" X="112" Y="58" Property="XXX_PROXY_SERVICE_URL" />
<Control Id="Next" Type="PushButton" X="236" Y="243" Width="56" Height="17" Default="yes" Text="!(loc.WixUINext)">
<Publish Event="DoAction" Value="ValidateProxyService" Order="1">1</Publish>
</Control>
<Control Id="Back" Type="PushButton" X="180" Y="243" Width="56" Height="17" Text="!(loc.WixUIBack)" />
<Control Id="Cancel" Type="PushButton" X="304" Y="243" Width="56" Height="17" Cancel="yes" Text="!(loc.WixUICancel)">
<Publish Event="SpawnDialog" Value="CancelDlg">1</Publish>
</Control>
</Dialog>
</UI>
</Fragment>
</Wix>
然后我写的自定义动作:
[CustomAction]
public static ActionResult ValidateProxyService(Session session)
{
try
{
string proxyServiceUrl = session["XXX_PROXY_SERVICE_URL"];
string message;
if (string.IsNullOrWhiteSpace(proxyServiceUrl))
{
session["XXX_PROXY_SERVICE_VALID"] = string.Empty;
MessageBox.Show(
"The proxy service URL is required.",
"Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
return ActionResult.Success;
}
else if (!ValidateUrl(proxyServiceUrl, out message))
{
if (MessageBox.Show(
message,
"Error",
MessageBoxButtons.OKCancel,
MessageBoxIcon.Warning) == DialogResult.Cancel)
{
session["XXX_PROXY_SERVICE_VALID"] = string.Empty;
return ActionResult.Success;
}
}
session["XXX_PROXY_SERVICE_VALID"] = "1";
}
catch (Exception ex)
{
session.Log("An error occurred during ValidateProxyService: {0}", ex);
return ActionResult.Failure;
}
return ActionResult.Success;
}
对正在进行的操作的一般概述是对话框要求输入URL并将其放在XXX_PROXY_SERVICE_URL属性中。按对话框上的“下一步”按钮时,它将运行自定义操作。然后,自定义操作将读取XXX_PROXY_SERVICE_URL并测试它是否有效并尝试加载页面。如果它无效或失败,则取消设置XXX_PROXY_SERVICE_VALID属性。
在安装程序的主UI中,我有:
<Publish Dialog="XXXServiceDlg" Control="Next" Event="NewDialog" Value="OtherDlg" Order="2">XXX_PROXY_SERVICE_VALID</Publish>
因此,如果服务无效,它将不会进入下一页。
一些警告:
需要填写的一些空白:
一旦弄明白这两件事情,就不应该对上述策略进行调整以验证任何用户输入。
答案 1 :(得分:0)
您可能需要重新提问。您正在谈论的凭据需要足够的权限才能作为服务运行 - 它们不会用于安装服务,正如您的问题所暗示的那样。安装本身将(或应该!)要求提升UAC系统并为您安装服务。
验证的第一部分基于调用LogonUser(),类似这样的API使用指南。
http://msdn.microsoft.com/en-us/library/windows/desktop/aa378184(v=vs.85).aspx
这里也有一些讨论: