ServiceInstallerDialogResult 枚举

定义

指定 ServiceInstallerDialog 窗体的返回值。

public enum class ServiceInstallerDialogResult
public enum ServiceInstallerDialogResult
type ServiceInstallerDialogResult = 
Public Enum ServiceInstallerDialogResult
继承
ServiceInstallerDialogResult

字段

Canceled 2

对话返回值为 Canceled。 这个值通常指示用户未设置帐户字段就退出了对话框。

OK 0

对话返回值为 OK。 这个值通常指示用户确认了帐户属性并按下了 OK 按钮来关闭对话。

UseSystem 1

使用系统帐户而不是用户帐户来安装服务。 这个值通常指示没有向用户显示对话框。 例如,将 Account 属性设置为 User 以外的值。

示例

以下示例使用 提示 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 使用此枚举来指示用户对对话框的响应。

适用于

另请参阅