Export (0) Print
Expand All

ServiceInstallerDialogResult Enumeration

Specifies the return value of a ServiceInstallerDialog form.

Namespace:  System.ServiceProcess.Design
Assembly:  System.ServiceProcess (in System.ServiceProcess.dll)

public enum ServiceInstallerDialogResult

Member nameDescription
CanceledThe dialog return value is Canceled. This value typically indicates that the user canceled out of the dialog without setting the account fields.
OKThe dialog return value is OK. This value typically indicates that the user confirmed the account properties and pressed the OK button to close the dialog.
UseSystemInstall the service with a system account rather than a user account. This value typically indicates that the dialog was not displayed to the user. For example, the ServiceProcessInstaller.Account property is set to something other than User.

The ServiceInstallerDialog.Result property uses this enumeration to indicate the user response to the dialog box.

The following example uses a ServiceInstallerDialog to prompt the user for a service installation account.

// 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. 
        svcDialog.TopMost = true;

        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", 

            if (result == DialogResult.Cancel)
                // Break out of loop. 
    } while (!accountSet);

    return accountSet;

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft