EventWaitHandle.GetAccessControl メソッド
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As EventWaitHandle Dim returnValue As EventWaitHandleSecurity returnValue = instance.GetAccessControl
名前付きシステム イベントのアクセス制御セキュリティを表す EventWaitHandleSecurity オブジェクト。


GetAccessControl メソッドは、(ビットごとの OR 演算を使用して組み合わされた) 次のフラグの組み合わせを使用して、AccessControlSections.Access、AccessControlSections.Owner、および AccessControlSections.Group の各アクセス許可を検索します。
このメソッドを呼び出すためには EventWaitHandleRights.ReadPermissions 権限がユーザーにあることが必要で、イベントは EventWaitHandleRights.ReadPermissions フラグで開かれている必要があります。

アクセス制御セキュリティを使用した名前付きシステム イベントのプロセス間の動作をデモンストレーションするコード例を次に示します。この例では、OpenExisting(String) メソッド オーバーロードを使用して、名前付きイベントが存在するかどうかをテストしています。
イベントが存在しない場合、初期所有権と、現在のユーザーによるイベントの使用を拒否しイベントに対する読み取りと変更のアクセス許可のみを付与するアクセス制御セキュリティでイベントが作成されます。
2 つのコマンド ウィンドウからコンパイルした例を実行すると、2 番目のコピーは OpenExisting(String) の呼び出しでアクセス違反例外をスローします。例外がキャッチされると、OpenExisting(String,EventWaitHandleRights) メソッド オーバーロードを使用し、アクセス許可の読み取りと変更に必要な権限で、イベントを待機します。
GetAccessControl メソッドを使用してアクセス許可が読み取られ、変更された後で、待機とシグナル通知に必要な権限でイベントが開かれます。3 つ目のコマンド ウィンドウからコンパイル済みの例を実行する場合、新しいアクセス許可を使用して実行されます。
Imports System Imports System.Threading Imports System.Security.AccessControl Friend Class Example <MTAThread> _ Friend Shared Sub Main() Const ewhName As String = "EventWaitHandleExample5" Dim ewh As EventWaitHandle = Nothing Dim doesNotExist as Boolean = False Dim unauthorized As Boolean = False ' The value of this variable is set by the event ' constructor. It is True if the named system event was ' created, and False if the named event already existed. ' Dim wasCreated As Boolean ' Attempt to open the named event. Try ' Open the event with (EventWaitHandleRights.Synchronize ' Or EventWaitHandleRights.Modify), to wait on and ' signal the named event. ' ewh = EventWaitHandle.OpenExisting(ewhName) Catch ex As WaitHandleCannotBeOpenedException Console.WriteLine("Named event does not exist.") doesNotExist = True Catch ex As UnauthorizedAccessException Console.WriteLine("Unauthorized access: {0}", ex.Message) unauthorized = True End Try ' There are three cases: (1) The event does not exist. ' (2) The event exists, but the current user doesn't ' have access. (3) The event exists and the user has ' access. ' If doesNotExist Then ' The event does not exist, so create it. ' Create an access control list (ACL) that denies the ' current user the right to wait on or signal the ' event, but allows the right to read and change ' security information for the event. ' Dim user As String = Environment.UserDomainName _ & "\" & Environment.UserName Dim ewhSec As New EventWaitHandleSecurity() Dim rule As New EventWaitHandleAccessRule(user, _ EventWaitHandleRights.Synchronize Or _ EventWaitHandleRights.Modify, _ AccessControlType.Deny) ewhSec.AddAccessRule(rule) rule = New EventWaitHandleAccessRule(user, _ EventWaitHandleRights.ReadPermissions Or _ EventWaitHandleRights.ChangePermissions, _ AccessControlType.Allow) ewhSec.AddAccessRule(rule) ' Create an EventWaitHandle object that represents ' the system event named by the constant 'ewhName', ' initially signaled, with automatic reset, and with ' the specified security access. The Boolean value that ' indicates creation of the underlying system object ' is placed in wasCreated. ' ewh = New EventWaitHandle(True, _ EventResetMode.AutoReset, ewhName, _ wasCreated, ewhSec) ' If the named system event was created, it can be ' used by the current instance of this program, even ' though the current user is denied access. The current ' program owns the event. Otherwise, exit the program. ' If wasCreated Then Console.WriteLine("Created the named event.") Else Console.WriteLine("Unable to create the event.") Return End If ElseIf unauthorized Then ' Open the event to read and change the access control ' security. The access control security defined above ' allows the current user to do this. ' Try ewh = EventWaitHandle.OpenExisting(ewhName, _ EventWaitHandleRights.ReadPermissions Or _ EventWaitHandleRights.ChangePermissions) ' Get the current ACL. This requires ' EventWaitHandleRights.ReadPermissions. Dim ewhSec As EventWaitHandleSecurity = _ ewh.GetAccessControl() Dim user As String = Environment.UserDomainName _ & "\" & Environment.UserName ' First, the rule that denied the current user ' the right to enter and release the event must ' be removed. Dim rule As New EventWaitHandleAccessRule(user, _ EventWaitHandleRights.Synchronize Or _ EventWaitHandleRights.Modify, _ AccessControlType.Deny) ewhSec.RemoveAccessRule(rule) ' Now grant the user the correct rights. ' rule = New EventWaitHandleAccessRule(user, _ EventWaitHandleRights.Synchronize Or _ EventWaitHandleRights.Modify, _ AccessControlType.Allow) ewhSec.AddAccessRule(rule) ' Update the ACL. This requires ' EventWaitHandleRights.ChangePermissions. ewh.SetAccessControl(ewhSec) Console.WriteLine("Updated event security.") ' Open the event with (EventWaitHandleRights.Synchronize ' Or EventWaitHandleRights.Modify), the rights required ' to wait on and signal the event. ' ewh = EventWaitHandle.OpenExisting(ewhName) Catch ex As UnauthorizedAccessException Console.WriteLine("Unable to change permissions: {0}", _ ex.Message) Return End Try End If ' Wait on the event, and hold it until the program ' exits. ' Try Console.WriteLine("Wait on the event.") ewh.WaitOne() Console.WriteLine("Event was signaled.") Console.WriteLine("Press the Enter key to signal the event and exit.") Console.ReadLine() Catch ex As UnauthorizedAccessException Console.WriteLine("Unauthorized access: {0}", _ ex.Message) Finally ewh.Set() End Try End Sub End Class
using System; using System.Threading; using System.Security.AccessControl; internal class Example { internal static void Main() { const string ewhName = "EventWaitHandleExample5"; EventWaitHandle ewh = null; bool doesNotExist = false; bool unauthorized = false; // The value of this variable is set by the event // constructor. It is true if the named system event was // created, and false if the named event already existed. // bool wasCreated; // Attempt to open the named event. try { // Open the event with (EventWaitHandleRights.Synchronize // | EventWaitHandleRights.Modify), to wait on and // signal the named event. // ewh = EventWaitHandle.OpenExisting(ewhName); } catch (WaitHandleCannotBeOpenedException) { Console.WriteLine("Named event does not exist."); doesNotExist = true; } catch (UnauthorizedAccessException ex) { Console.WriteLine("Unauthorized access: {0}", ex.Message); unauthorized = true; } // There are three cases: (1) The event does not exist. // (2) The event exists, but the current user doesn't // have access. (3) The event exists and the user has // access. // if (doesNotExist) { // The event does not exist, so create it. // Create an access control list (ACL) that denies the // current user the right to wait on or signal the // event, but allows the right to read and change // security information for the event. // string user = Environment.UserDomainName + "\\" + Environment.UserName; EventWaitHandleSecurity ewhSec = new EventWaitHandleSecurity(); EventWaitHandleAccessRule rule = new EventWaitHandleAccessRule(user, EventWaitHandleRights.Synchronize | EventWaitHandleRights.Modify, AccessControlType.Deny); ewhSec.AddAccessRule(rule); rule = new EventWaitHandleAccessRule(user, EventWaitHandleRights.ReadPermissions | EventWaitHandleRights.ChangePermissions, AccessControlType.Allow); ewhSec.AddAccessRule(rule); // Create an EventWaitHandle object that represents // the system event named by the constant 'ewhName', // initially signaled, with automatic reset, and with // the specified security access. The Boolean value that // indicates creation of the underlying system object // is placed in wasCreated. // ewh = new EventWaitHandle(true, EventResetMode.AutoReset, ewhName, out wasCreated, ewhSec); // If the named system event was created, it can be // used by the current instance of this program, even // though the current user is denied access. The current // program owns the event. Otherwise, exit the program. // if (wasCreated) { Console.WriteLine("Created the named event."); } else { Console.WriteLine("Unable to create the event."); return; } } else if (unauthorized) { // Open the event to read and change the access control // security. The access control security defined above // allows the current user to do this. // try { ewh = EventWaitHandle.OpenExisting(ewhName, EventWaitHandleRights.ReadPermissions | EventWaitHandleRights.ChangePermissions); // Get the current ACL. This requires // EventWaitHandleRights.ReadPermissions. EventWaitHandleSecurity ewhSec = ewh.GetAccessControl(); string user = Environment.UserDomainName + "\\" + Environment.UserName; // First, the rule that denied the current user // the right to enter and release the event must // be removed. EventWaitHandleAccessRule rule = new EventWaitHandleAccessRule(user, EventWaitHandleRights.Synchronize | EventWaitHandleRights.Modify, AccessControlType.Deny); ewhSec.RemoveAccessRule(rule); // Now grant the user the correct rights. // rule = new EventWaitHandleAccessRule(user, EventWaitHandleRights.Synchronize | EventWaitHandleRights.Modify, AccessControlType.Allow); ewhSec.AddAccessRule(rule); // Update the ACL. This requires // EventWaitHandleRights.ChangePermissions. ewh.SetAccessControl(ewhSec); Console.WriteLine("Updated event security."); // Open the event with (EventWaitHandleRights.Synchronize // | EventWaitHandleRights.Modify), the rights required // to wait on and signal the event. // ewh = EventWaitHandle.OpenExisting(ewhName); } catch (UnauthorizedAccessException ex) { Console.WriteLine("Unable to change permissions: {0}", ex.Message); return; } } // Wait on the event, and hold it until the program // exits. // try { Console.WriteLine("Wait on the event."); ewh.WaitOne(); Console.WriteLine("Event was signaled."); Console.WriteLine("Press the Enter key to signal the event and exit."); Console.ReadLine(); } catch (UnauthorizedAccessException ex) { Console.WriteLine("Unauthorized access: {0}", ex.Message); } finally { ewh.Set(); } } }
using namespace System; using namespace System::Threading; using namespace System::Security::AccessControl; using namespace System::Security::Permissions; public ref class Example { public: [SecurityPermissionAttribute(SecurityAction::Demand,Flags=SecurityPermissionFlag::UnmanagedCode)] static void Main() { String^ ewhName = L"EventWaitHandleExample5"; EventWaitHandle^ ewh = nullptr; bool doesNotExist = false; bool unauthorized = false; // The value of this variable is set by the event // constructor. It is true if the named system event was // created, and false if the named event already existed. // bool wasCreated; // Attempt to open the named event. try { // Open the event with (EventWaitHandleRights.Synchronize // | EventWaitHandleRights.Modify), to wait on and // signal the named event. // ewh = EventWaitHandle::OpenExisting( ewhName ); } catch ( WaitHandleCannotBeOpenedException^ ) { Console::WriteLine( L"Named event does not exist." ); doesNotExist = true; } catch ( UnauthorizedAccessException^ ex ) { Console::WriteLine( L"Unauthorized access: {0}", ex->Message ); unauthorized = true; } // There are three cases: (1) The event does not exist. // (2) The event exists, but the current user doesn't // have access. (3) The event exists and the user has // access. // if ( doesNotExist ) { // The event does not exist, so create it. // Create an access control list (ACL) that denies the // current user the right to wait on or signal the // event, but allows the right to read and change // security information for the event. // String^ user = String::Concat( Environment::UserDomainName, L"\\" , Environment::UserName ); EventWaitHandleSecurity^ ewhSec = gcnew EventWaitHandleSecurity; //following constructor fails EventWaitHandleAccessRule^ rule = gcnew EventWaitHandleAccessRule( user, static_cast<EventWaitHandleRights>( EventWaitHandleRights::Synchronize | EventWaitHandleRights::Modify), AccessControlType::Deny ); ewhSec->AddAccessRule( rule ); rule = gcnew EventWaitHandleAccessRule( user, static_cast<EventWaitHandleRights>( EventWaitHandleRights::ReadPermissions | EventWaitHandleRights::ChangePermissions), AccessControlType::Allow ); ewhSec->AddAccessRule( rule ); // Create an EventWaitHandle object that represents // the system event named by the constant 'ewhName', // initially signaled, with automatic reset, and with // the specified security access. The Boolean value that // indicates creation of the underlying system object // is placed in wasCreated. // ewh = gcnew EventWaitHandle( true, EventResetMode::AutoReset, ewhName, wasCreated, ewhSec ); // If the named system event was created, it can be // used by the current instance of this program, even // though the current user is denied access. The current // program owns the event. Otherwise, exit the program. // if ( wasCreated ) { Console::WriteLine( L"Created the named event." ); } else { Console::WriteLine( L"Unable to create the event." ); return; } } else if ( unauthorized ) { // Open the event to read and change the access control // security. The access control security defined above // allows the current user to do this. // try { ewh = EventWaitHandle::OpenExisting( ewhName, static_cast<EventWaitHandleRights>( EventWaitHandleRights::ReadPermissions | EventWaitHandleRights::ChangePermissions) ); // Get the current ACL. This requires // EventWaitHandleRights.ReadPermissions. EventWaitHandleSecurity^ ewhSec = ewh->GetAccessControl(); String^ user = String::Concat( Environment::UserDomainName, L"\\" , Environment::UserName ); // First, the rule that denied the current user // the right to enter and release the event must // be removed. EventWaitHandleAccessRule^ rule = gcnew EventWaitHandleAccessRule( user, static_cast<EventWaitHandleRights>( EventWaitHandleRights::Synchronize | EventWaitHandleRights::Modify), AccessControlType::Deny ); ewhSec->RemoveAccessRule( rule ); // Now grant the user the correct rights. // rule = gcnew EventWaitHandleAccessRule( user, static_cast<EventWaitHandleRights>( EventWaitHandleRights::Synchronize | EventWaitHandleRights::Modify), AccessControlType::Allow ); ewhSec->AddAccessRule( rule ); // Update the ACL. This requires // EventWaitHandleRights.ChangePermissions. ewh->SetAccessControl( ewhSec ); Console::WriteLine( L"Updated event security." ); // Open the event with (EventWaitHandleRights.Synchronize // | EventWaitHandleRights.Modify), the rights required // to wait on and signal the event. // ewh = EventWaitHandle::OpenExisting( ewhName ); } catch ( UnauthorizedAccessException^ ex ) { Console::WriteLine( L"Unable to change permissions: {0}", ex->Message ); return; } } // Wait on the event, and hold it until the program // exits. // try { Console::WriteLine( L"Wait on the event." ); ewh->WaitOne(); Console::WriteLine( L"Event was signaled." ); Console::WriteLine( L"Press the Enter key to signal the event and exit." ); Console::ReadLine(); } catch ( UnauthorizedAccessException^ ex ) { Console::WriteLine( L"Unauthorized access: {0}", ex->Message ); } finally { ewh->Set(); } } }; int main() { Example::Main(); }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からEventWaitHandle.GetAccessControl メソッドを検索する場合は、下記のリンクをクリックしてください。

- EventWaitHandle.GetAccessControl メソッドのページへのリンク