.NET Framework クラス ライブラリ リファレンス |
ServiceInstallerDialog クラス
アセンブリ: System.ServiceProcess (system.serviceprocess.dll 内)
構文Public Class ServiceInstallerDialog Inherits Form
public class ServiceInstallerDialog extends Form
public class ServiceInstallerDialog extends Form
解説通常、ServiceInstallerDialog クラスはコード内で直接使用しません。このダイアログ ボックスは、Windows サービス アプリケーションのインストール ユーティリティによって使用されるのが一般的です。
ServiceProcessInstaller オブジェクトの Account が User に設定されており、Username または Password のいずれかが空の文字列 ("") の場合、インストール ユーティリティは ServiceInstallerDialog を使用して、これらの値の入力を要求するプロンプトを表示します。
ServiceInstallerDialog は Form から派生します。このダイアログを表示および操作するには、Form クラスのメソッドとプロパティを使用します。たとえば、ShowDialog を使用してフォームを表示し、Result を確認した後で、Username および Password の各プロパティの入力テキストを検証します。
メモ |
|---|
| ServiceInstallerDialog では、指定したアカウントの資格情報および特権を確認しません。たとえば、ユーザーがそのコンピュータでは無効なアカウント名とパスワードを入力した場合や、ユーザー アカウントにサービスとして実行するための適切な特権がない場合があります。インストールされているサービスが正常に実行できるように、ユーザー入力を検証してください。 |
使用例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
継承階層System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.Control
System.Windows.Forms.ScrollableControl
System.Windows.Forms.ContainerControl
System.Windows.Forms.Form
System.ServiceProcess.Design.ServiceInstallerDialog
スレッド セーフ
プラットフォーム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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
参照.gif)