ServiceInstallerDialogResult 列舉
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指定 ServiceInstallerDialog 表單的傳回值。
public enum class ServiceInstallerDialogResult
public enum ServiceInstallerDialogResult
type ServiceInstallerDialogResult =
Public Enum ServiceInstallerDialogResult
- 繼承
欄位
Canceled | 2 | 對話方塊傳回值為 |
OK | 0 | 對話方塊傳回值為 |
UseSystem | 1 | 以系統帳戶安裝此服務,而非使用者帳戶。 這個值通常表示不會向使用者顯示此對話方塊。 例如, Account 屬性設為 |
範例
下列範例會使用 ServiceInstallerDialog 來提示使用者輸入服務安裝帳戶。
// Prompt the user for service installation account values.
public:
static bool GetServiceAccount( interior_ptr<ServiceProcessInstaller^> svcInst )
{
bool accountSet = false;
ServiceInstallerDialog^ svcDialog = gcnew ServiceInstallerDialog;
// Query the user for the service account type.
do
{
svcDialog->TopMost = true;
svcDialog->ShowDialog();
if ( svcDialog->Result == ServiceInstallerDialogResult::OK )
{
// Do a very simple validation on the user
// input. Check to see whether the user name
// or password is blank.
if ( (svcDialog->Username->Length > 0) && (svcDialog->Password->Length > 0) )
{
// Use the account and password.
accountSet = true;
( *svcInst)->Account = ServiceAccount::User;
( *svcInst)->Username = svcDialog->Username;
( *svcInst)->Password = svcDialog->Password;
}
}
else
if ( svcDialog->Result == ServiceInstallerDialogResult::UseSystem )
{
( *svcInst)->Account = ServiceAccount::LocalSystem;
( *svcInst)->Username = nullptr;
( *svcInst)->Password = nullptr;
accountSet = true;
}
if ( !accountSet )
{
// Display a message box. Tell the user to
// enter a valid user and password, or cancel
// out to leave the service account alone.
DialogResult result;
result = MessageBox::Show( "Invalid user name or password for service installation."
" Press Cancel to leave the service account unchanged.", "Change Service Account",
MessageBoxButtons::OKCancel, MessageBoxIcon::Hand );
if ( result == DialogResult::Cancel )
{
// Break out of loop.
break;
}
}
}
while ( !accountSet );
return accountSet;
}
// Prompt the user for service installation account values.
public static bool GetServiceAccount(ref ServiceProcessInstaller svcInst)
{
bool accountSet = false;
ServiceInstallerDialog svcDialog = new ServiceInstallerDialog();
// Query the user for the service account type.
do
{
svcDialog.TopMost = true;
svcDialog.ShowDialog();
if (svcDialog.Result == ServiceInstallerDialogResult.OK)
{
// Do a very simple validation on the user
// input. Check to see whether the user name
// or password is blank.
if ((svcDialog.Username.Length > 0) &&
(svcDialog.Password.Length > 0) )
{
// Use the account and password.
accountSet = true;
svcInst.Account = ServiceAccount.User;
svcInst.Username = svcDialog.Username;
svcInst.Password = svcDialog.Password;
}
}
else if (svcDialog.Result == ServiceInstallerDialogResult.UseSystem)
{
svcInst.Account = ServiceAccount.LocalSystem;
svcInst.Username = null;
svcInst.Password = null;
accountSet = true;
}
if (!accountSet )
{
// Display a message box. Tell the user to
// enter a valid user and password, or cancel
// out to leave the service account alone.
DialogResult result;
result = MessageBox.Show("Invalid user name or password for service installation."+
" Press Cancel to leave the service account unchanged.",
"Change Service Account",
MessageBoxButtons.OKCancel,
MessageBoxIcon.Hand);
if (result == DialogResult.Cancel)
{
// Break out of loop.
break;
}
}
} while (!accountSet);
return accountSet;
}
備註
屬性 ServiceInstallerDialog.Result 會使用這個列舉來指出使用者對對話方塊的回應。