Пример #1
0
        public static IntPtr _CreateEvent(bool bManualReset, bool bInitialState, string lpName)
        {
            SECURITY_DESCRIPTOR sd = new SECURITY_DESCRIPTOR();
            InitializeSecurityDescriptor(ref sd, SECURITY_DESCRIPTOR_REVISION);
            SetSecurityDescriptorDacl(ref sd, true, IntPtr.Zero, false);
            GCHandle sdHandle = GCHandle.Alloc(sd, GCHandleType.Pinned);

            SECURITY_ATTRIBUTES sa = new SECURITY_ATTRIBUTES();
            sa.nLength = Marshal.SizeOf(sa);
            sa.lpSecurityDescriptor = sdHandle.AddrOfPinnedObject();
            sa.bInheritHandle = 0;
            GCHandle saHandle = GCHandle.Alloc(sa, GCHandleType.Pinned);

            System.IntPtr hEvent = IntPtr.Zero;
            hEvent = CreateEvent(
                saHandle.AddrOfPinnedObject(),
                bManualReset,
                bInitialState,
                lpName
            );

            saHandle.Free();
            sdHandle.Free();
            if (hEvent == (System.IntPtr)(int)-1)
            {
                return IntPtr.Zero;
            }
            return hEvent;
        }
Пример #2
0
        public static IntPtr _CreateNamedPipe(string lpName, uint dwOpenMode,
           uint dwPipeMode, uint nMaxInstances, uint nOutBufferSize, uint nInBufferSize,
           uint nDefaultTimeOut)
        {
            SECURITY_DESCRIPTOR sd = new SECURITY_DESCRIPTOR();
            InitializeSecurityDescriptor(ref sd, SECURITY_DESCRIPTOR_REVISION);
            SetSecurityDescriptorDacl(ref sd, true, IntPtr.Zero, false);
            GCHandle sdHandle = GCHandle.Alloc(sd, GCHandleType.Pinned);

            SECURITY_ATTRIBUTES sa = new SECURITY_ATTRIBUTES();
            sa.nLength = Marshal.SizeOf(sa);
            sa.lpSecurityDescriptor = sdHandle.AddrOfPinnedObject();
            sa.bInheritHandle = 0;
            GCHandle saHandle = GCHandle.Alloc(sa, GCHandleType.Pinned);

            System.IntPtr hPipe = IntPtr.Zero;
            hPipe = CreateNamedPipe(
                lpName,
                dwOpenMode,
                dwPipeMode,
                nMaxInstances,
                nOutBufferSize,
                nInBufferSize,
                nDefaultTimeOut,
                saHandle.AddrOfPinnedObject()
            );

            saHandle.Free();
            sdHandle.Free();
            if (hPipe == (System.IntPtr)(int)-1)
            {
                return IntPtr.Zero;
            }
            return hPipe;
        }
Пример #3
0
        public static IntPtr _CreateFile(
           string lpFileName,
           EFileAccess dwDesiredAccess,
           EFileShare dwShareMode,
           ECreationDisposition dwCreationDisposition,
           EFileAttributes dwFlagsAndAttributes,
           IntPtr hTemplateFile
            )
        {
            SECURITY_DESCRIPTOR sd = new SECURITY_DESCRIPTOR();
            InitializeSecurityDescriptor(ref sd, SECURITY_DESCRIPTOR_REVISION);
            SetSecurityDescriptorDacl(ref sd, true, IntPtr.Zero, false);
            GCHandle sdHandle = GCHandle.Alloc(sd, GCHandleType.Pinned); 

            SECURITY_ATTRIBUTES sa = new SECURITY_ATTRIBUTES();
            sa.nLength = Marshal.SizeOf(sa);
            sa.lpSecurityDescriptor = sdHandle.AddrOfPinnedObject(); 
            sa.bInheritHandle = 0;
            GCHandle saHandle = GCHandle.Alloc(sa, GCHandleType.Pinned); 

            System.IntPtr hFile = IntPtr.Zero;
            hFile = CreateFile(
                lpFileName,
                dwDesiredAccess,
                dwShareMode,
                saHandle.AddrOfPinnedObject(),
                dwCreationDisposition,
                dwFlagsAndAttributes,
                hTemplateFile
            );

            saHandle.Free();
            sdHandle.Free();
            if (hFile == (System.IntPtr)(int)-1)
            {
                return IntPtr.Zero;
            }
            return hFile;
        }