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.
GetSecurityInfo (advapi32)
.
Local or remote files or directories on an NTFS file system
Named pipes
Local or remote printers
Local or remote Windows services
Network shares
Registry keys
Semaphores, events, mutexes, and waitable timers
Processes, threads, jobs, and file-mapping objects
Interactive service window stations and desktops
Directory service objects
C# Signature:
[DllImport("advapi32.dll", SetLastError=true)]
static extern uint GetSecurityInfo(
IntPtr handle,
HANDLE handle,
SE_OBJECT_TYPE ObjectType,
SECURITY_INFORMATION SecurityInfo,
out IntPtr pSidOwner,
out IntPtr pSidGroup,
out IntPtr pDacl,
out IntPtr pSacl,
out IntPtr pSecurityDescriptor);
VB Signature:
<DllImport("advapi32.dll", setlasterror:=True)> _
Private Shared Function GetSecurityInfo( _
ByRef hObject As IntPtr, _
ByRef ObjectType As SE_OBJECT_TYPE, _
ByRef SecurityInfo As SECURITY_INFORMATION, _
ByRef pSidOwner As IntPtr, _
ByRef pSidGroup As IntPtr, _
ByRef pDacl As IntPtr, _
ByRef pSacl As IntPtr, _
ByRef pSD As IntPtr) _
As Integer
End Function
Declare Function GetSecurityInfo Lib "advapi32.dll" (TODO) As TODO
User-Defined Types:
Alternative Managed API:
Do you know one? Please contribute it!
Notes:
I am currently trying to implement this function to get the security attributes for Network Shares.
Tips & Tricks:
Please add some!
Sample Code:
C#
Compiled for 2.0 but I guess it should work for 1.1. (Of course 2.0 provides the AccessControl namespace which makes this sample only interesting for knowing the basics of how it is done)
This sample only retrieves the owner of the object (in this case a file but could be other object if you change the objectType)
class Program
{
[DllImport("advapi32.dll", SetLastError = true)]
static extern int GetSecurityInfo(
IntPtr handle,
SE_OBJECT_TYPE objectType,
SECURITY_INFORMATION securityInfo,
out IntPtr sidOwner,
out IntPtr sidGroup,
out IntPtr dacl,
out IntPtr sacl,
out IntPtr securityDescriptor);
returnValue = GetSecurityInfo(fileStream.Handle, SE_OBJECT_TYPE.SE_FILE_OBJECT, SECURITY_INFORMATION.OWNER_SECURITY_INFORMATION | SECURITY_INFORMATION.DACL_SECURITY_INFORMATION, out ownerSid, out groupSid, out dacl, out sacl, out securityDescriptor);
You can use the GetSecurityInfo function with the following types of objects
12/1/2012 10:58:24 AM - -76.120.237.99
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).