Semaphore.GetAccessControl Method ()

 

Gets the access control security for a named system semaphore.

Namespace:   System.Threading
Assembly:  System (in System.dll)

member GetAccessControl : unit -> SemaphoreSecurity

Return Value

Type: System.Security.AccessControl.SemaphoreSecurity

A SemaphoreSecurity object that represents the access control security for the named system semaphore.

Exception Condition
UnauthorizedAccessException

The current Semaphore object represents a named system semaphore, and the user does not have SemaphoreRights.ReadPermissions rights.

-or-

The current Semaphore object represents a named system semaphore and was not opened with SemaphoreRights.ReadPermissions rights.

NotSupportedException

Not supported for Windows 98 or Windows Millennium Edition.

The GetAccessControl method uses the following combination of flags (combined using the bitwise OR operation) to search for permissions: AccessControlSections.Access, AccessControlSections.Owner, and AccessControlSections.Group.

The user must have SemaphoreRights.ReadPermissions rights to call this method, and the semaphore must have been opened with SemaphoreRights.ReadPermissions rights.

On a local semaphore, access control security is irrelevant. If the Semaphore object does not represent a named system semaphore, this method returns a SemaphoreSecurity object that grants all rights to any user.

The following code example demonstrates the cross-process behavior of a named semaphore with access control security. The example uses the OpenExisting(String) method overload to test for the existence of a named semaphore.

If the semaphore does not exist, it is created with a maximum count of two and with access control security that denies the current user the right to use the semaphore, but grants the right to read and change permissions on the semaphore.

If you run the compiled example from two command windows, the second copy will throw an access violation exception on the call to the OpenExisting(String) method. The exception is caught, and the example uses the OpenExisting(String, SemaphoreRights) method overload to open the semaphore with the rights needed to read and change the permissions. The access control security for the system semaphore is obtained using the GetAccessControl method.

After the permissions are changed, the semaphore is opened with the rights required to enter and release. If you run the compiled example from a third command window, it runs using the new permissions.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 2.0
Return to top
Show: