ServiceInstallerDialog.Result プロパティ
アセンブリ: System.ServiceProcess (system.serviceprocess.dll 内)
構文Dim instance As ServiceInstallerDialog Dim value As ServiceInstallerDialogResult value = instance.Result
ダイアログ ボックスに対するユーザーの応答を示す ServiceInstallerDialogResult。既定値は OK です。
解説ShowDialog を使用してサービス インストール アカウントの入力をユーザーに要求してから、Result の値を確認してください。この値が OK の場合は、入力値 Username と Password が有効であることを検証してください。
.NET Framework のセキュリティ
プラットフォームWindows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
参照ServiceInstallerDialogResult 列挙体
アセンブリ: System.ServiceProcess (system.serviceprocess.dll 内)
構文Public Enumeration ServiceInstallerDialogResult
メンバ| メンバ名 | 説明 | |
|---|---|---|
| Canceled | ダイアログの戻り値は Canceled です。通常、この値はユーザーがアカウントのフィールドを設定せずにダイアログをキャンセルして終了したことを示します。 | |
| OK | ダイアログの戻り値は OK です。通常、この値はユーザーがアカウントのプロパティを確認し、[OK] ボタンを押してダイアログを閉じたことを示します。 | |
| UseSystem | ユーザー アカウントではなく、システム アカウントを使用してサービスをインストールします。通常、この値はダイアログがユーザーに表示されなかったことを示します。たとえば、ServiceProcessInstaller.Account プロパティが User 以外に設定されています。 |
解説
使用例ServiceInstallerDialog を使用して、ユーザーにサービス インストール アカウントを入力するように要求するプロンプトを表示する例を次に示します。
// 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; }
// 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 boolean GetServiceAccount(ServiceProcessInstaller svcInst) { boolean accountSet = false; ServiceInstallerDialog svcDialog = new ServiceInstallerDialog(); // Query the user for the service account type. do { svcDialog.set_TopMost(true); svcDialog.ShowDialog(); if (svcDialog.get_Result().Equals(ServiceInstallerDialogResult.OK)) { // Do a very simple validation on the user // input. Check to see whether the user name // or password is blank. if (svcDialog.get_Username().get_Length() > 0 && svcDialog.get_Password().get_Length() > 0) { // Use the account and password. accountSet = true; svcInst.set_Account(ServiceAccount.User); svcInst.set_Username(svcDialog.get_Username()); svcInst.set_Password(svcDialog.get_Password()); } } else { if (svcDialog.get_Result().Equals(ServiceInstallerDialogResult. UseSystem)) { svcInst.set_Account(ServiceAccount.LocalSystem); svcInst.set_Username(null); svcInst.set_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.Equals(DialogResult.Cancel)) { // Break out of loop. break; } } } while (!(accountSet)); return accountSet; } //GetServiceAccount
プラットフォームWindows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
参照- ServiceInstallerDialogResultのページへのリンク