Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than advapi32, prefix the name with the module name and a period.
GetNamedSecurityInfo (advapi32)
.
Резюме: Функция GetNamedSecurityInfo возвращает копию дескриптора безопасности для объекта, заданного именем.
C# Signature:
[DllImport("advapi32.dll", CharSet=CharSet.Auto)]
static extern uint GetNamedSecurityInfo(
string pObjectName,
SE_OBJECT_TYPE ObjectType,
SECURITY_INFORMATION SecurityInfo,
out IntPtr pSidOwner,
out IntPtr pSidGroup,
out IntPtr pDacl,
out IntPtr pSacl,
out IntPtr pSecurityDescriptor);
VB Signature:
VB.Net Signature:
Declare Function GetNamedSecurityInfo Lib "advapi32.dll" ( _
ByVal pObjectName As String, _
ByVal ObjectType As SE_OBJECT_TYPE, _
ByVal SecurityInfo As SECURITY_INFORMATION, _
ByRef pSidOwner As IntPtr, _
ByRef pSidGroup As IntPtr, _
ByRef pDacl As IntPtr, _
ByRef pSacl As IntPtr, _
ByRef pSecurityDescriptor As IntPtr) As Integer
uint errorReturn=GetNamedSecurityInfo(UnicodeHeader+objectName, SE_OBJECT_TYPE.SE_FILE_OBJECT,sFlags,out pSid, out pZero, out pZero, out pZero, out psd);
VB.Net Sample Code:
' Type of Securable Object we are operating in this sample code
Private Const SE_FILE_OBJECT = 1&
if (errorReturn != 0)
{
throw(new Exception("An error of code: "+errorReturn+" has occured"));
}
' The Security Information constants required
Private Const DACL_SECURITY_INFORMATION = 4&
int bufferSize = 64;
int accounLength = bufferSize;
int domainLength = bufferSize;
int sidNameUse = 0;
Dim pSecDesc, pOldDACL As IntPtr
Dim Win32Error As Win32Exception
Dim ret As Integer
StringBuilder account = new StringBuilder(bufferSize);
StringBuilder domain = new StringBuilder(bufferSize);
' get the Security Descriptor and DACL
ret = GetNamedSecurityInfo(strPath, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, Nothing, Nothing, pOldDACL, Nothing, pSecDesc)
If ret <> 0 Then
Win32Error = New Win32Exception(ret)
Throw New Exception(Win32Error.Message)
End If
if (!LookupAccountSid(null, pSid, account, ref accounLength, domain, ref domainLength, out sidNameUse))
{
throw (Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error()));
}
return domain+@"\"+account;
}
Alternative Managed API:
With .NET v2.0 you can use the classes in System.Security.AccessControl to duplicate most of this functionality.
VB.Net Sample Code:
' Type of Securable Object we are operating in this sample code
Private Const SE_FILE_OBJECT = 1&
using System.Security.AccessControl;
using System.Security.Principal;
' The Security Information constants required
Private Const DACL_SECURITY_INFORMATION = 4&
public static string GetFileObjectOwner(string objectName)
{
FileSecurity pSD = new FileSecurity(objectName, AccessControlSections.Owner);
Dim pSecDesc, pOldDACL As IntPtr
Dim Win32Error As Win32Exception
Dim ret As Integer
NTAccount ownerName = (NTAccount)(pSD.GetOwner(typeof(NTAccount)));
/* The username is returned in SAM form (domain\username) */
' get the Security Descriptor and DACL
ret = GetNamedSecurityInfo(strPath, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, Nothing, Nothing, pOldDACL, Nothing, pSecDesc)
If ret <> 0 Then
Win32Error = New Win32Exception(ret)
Throw New Exception(Win32Error.Message)
End If
return ownerName.ToString();
}
Alternative Managed API:
С .NET v2.0 Вы можете использовать классы из System.Security.AccessControl для большинства этих функциональностей.
using System.Security.AccessControl;
using System.Security.Principal;
public static string GetFileObjectOwner(string objectName)
{
FileSecurity pSD = new FileSecurity(objectName, AccessControlSections.Owner);
NTAccount ownerName = (NTAccount)(pSD.GetOwner(typeof(NTAccount)));
/* The username is returned in SAM form (domain\username) */
The GetNamedSecurityInfo function retrieves a copy of the security descriptor for an object specified by name.
4/22/2014 1:00:11 PM - 192.168.101.2
The GetNamedSecurityInfo function retrieves a copy of the security descriptor for an object specified by name.
4/22/2014 1:00:11 PM - 192.168.101.2
Indicates a type of object that supports security when calling functions such as GetSecurityInfo and SetSecurityInfo.
3/16/2007 7:43:11 AM - -80.212.75.179
Identifies the object-related security information to be set by SetNamedSecurityInfo
2/7/2014 3:57:04 PM - -202.1.96.195
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).