Exemple #1
0
        public IpcUserRights(UserRights userRights)
            : this()
        {
            user          = new IpcUser();
            user.userType = userRights.UserIdType;
            user.userID   = userRights.UserId;
            cRights       = (uint)userRights.Rights.Count;

            // Allocate memory for the right string array
            rgwszRights = Marshal.AllocHGlobal(userRights.Rights.Count * Marshal.SizeOf(typeof(IntPtr)));

            // go to the first right string entry
            IntPtr currentRightPtr = rgwszRights;

            foreach (string right in userRights.Rights)
            {
                // the right string itself
                IntPtr RightStringPtr = Marshal.StringToHGlobalUni(right);

                // assign the pointer
                Marshal.WriteIntPtr(currentRightPtr, 0, RightStringPtr);

                // go to the next right string entry
                currentRightPtr = new IntPtr(currentRightPtr.ToInt64() + Marshal.SizeOf(typeof(IntPtr)));
            }
        }
        public IpcUserRights(UserRights userRights)
            : this()
        {
            user = new IpcUser();
            user.userType = userRights.UserIdType;
            user.userID = userRights.UserId;
            cRights = (uint)userRights.Rights.Count;

            // Allocate memory for the right string array
            rgwszRights = Marshal.AllocHGlobal(userRights.Rights.Count * Marshal.SizeOf(typeof(IntPtr)));

            // go to the first right string entry
            IntPtr currentRightPtr = rgwszRights;

            foreach (string right in userRights.Rights)
            {
                // the right string itself
                IntPtr RightStringPtr = Marshal.StringToHGlobalUni(right);

                // assign the pointer
                Marshal.WriteIntPtr(currentRightPtr, 0, RightStringPtr);

                // go to the next right string entry
                currentRightPtr = new IntPtr(currentRightPtr.ToInt64() + Marshal.SizeOf(typeof(IntPtr)));
            }
        }
        // IPC_LI_OWNER - http://msdn.microsoft.com/en-us/library/windows/desktop/hh535287(v=vs.85).aspx
        public static void IpcSetLicenseOwner(SafeInformationProtectionLicenseHandle licenseHandle, string owner)
        {
            int hr = 0;
            IntPtr pvLicenseInfo = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IpcUser)));
            try
            {
                // Create a userinfo object
                IpcUser uInfo = new IpcUser();
                uInfo.userID = owner;
                uInfo.userType = UserIdType.Email;

                Marshal.StructureToPtr(uInfo, pvLicenseInfo, false);
                hr = UnsafeNativeMethods.IpcSetLicenseProperty(
                                licenseHandle,
                                false,
                                (uint)LicensePropertyType.Owner,
                                pvLicenseInfo);
                ThrowOnErrorCode(hr);
            }
            finally
            {
                Marshal.FreeHGlobal(pvLicenseInfo);
            }
        }