Ejemplo n.º 1
0
        private void Destroy()
        {
            User32.SetThreadDesktop(realDesktopHandle);

            Switch(shouldDisplayDesktop);

            User32.CloseDesktop(testDesktopHandle);
        }
Ejemplo n.º 2
0
        public void Delete()
        {
            RegistryKey userKey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", RegistryKeyPermissionCheck.ReadWriteSubTree);
            string      value   = (string)userKey?.GetValue("Desktop");

            userKey?.SetValue("Desktop", @"%USERPROFILE%\Desktop", RegistryValueKind.ExpandString);

            User32.SetThreadDesktop(normalDesktop);
            User32.SwitchDesktop(normalDesktop);
            User32.SetThreadDesktop(normalDesktop);
            User32.CloseDesktop(HandleDesktop);

            //Dispose();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create a processes with an access token of another user requires
        /// us to modify the desktop ACL to allow everybody to have access to it.
        ///
        /// This requires the SeSecurityPrivilege.
        /// This code has been heavily inspired/taken from Invoke-TokenManipulation.
        /// </summary>
        private void InnerSetDesktopACL()
        {
            this.InnerElevateProcess(PrivilegeConstants.SeSecurityPrivilege);

            var winAccess = (uint)ACCESS_MASK.ACCESS_SYSTEM_SECURITY;

            winAccess |= (uint)ACCESS_MASK.WRITE_DAC;
            winAccess |= (uint)ACCESS_MASK.READ_CONTROL;

            IntPtr hWinSta = User32.OpenWindowStation("WinSta0", false, winAccess);

            if (hWinSta == IntPtr.Zero)
            {
                Logger.GetInstance().Error($"Failed to open handle to window station. OpenWindowStation failed with error code: {Kernel32.GetLastError()}");
                throw new Exception();
            }

            Logger.GetInstance().Debug("Configuring the current Window Station ACL to allow everyone all access.");
            this.InnerSetACLAllowEveryone(hWinSta);

            if (!User32.CloseWindowStation(hWinSta))
            {
                Logger.GetInstance().Error($"Failed to release handle to window station. CloseWindowStation failed with error code: {Kernel32.GetLastError()}");
                throw new Exception();
            }

            var desktopAccess = Constants.DESKTOP_GENERIC_ALL | (uint)ACCESS_MASK.WRITE_DAC;

            IntPtr hDesktop = User32.OpenDesktop("default", 0, false, desktopAccess);

            if (hDesktop == IntPtr.Zero)
            {
                Logger.GetInstance().Error($"Failed to open handle to the default desktop. OpenDesktop failed with error code: {Kernel32.GetLastError()}");
                throw new Exception();
            }

            Logger.GetInstance().Debug("Configuring the current desktop ACL to allow everyone all access.");
            this.InnerSetACLAllowEveryone(hDesktop);

            if (!User32.CloseDesktop(hDesktop))
            {
                Logger.GetInstance().Error($"Failed to close handle to the default desktop. CloseDesktop failed with error code: {Kernel32.GetLastError()}");
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Closes the handle to a desktop.
        /// </summary>
        /// <returns>True if an open handle was successfully closed.</returns>
        public bool Close()
        {
            // make sure object isnt disposed.
            CheckDisposed();

            // check there is a desktop open.
            if (DesktopHandle == IntPtr.Zero)
            {
                return(true);
            }

            // close the desktop.
            var result = User32.CloseDesktop(DesktopHandle);

            if (result)
            {
                DesktopHandle = IntPtr.Zero;
            }

            return(result);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Closes the handle to a desktop
        /// </summary>
        /// <returns>True if an open handle was successfully closed.</returns>
        public bool Close()
        {
            // make sure object isnt disposed
            CheckDisposed();

            // check there is a desktop open
            if (_desktopHandle != IntPtr.Zero)
            {
                // close the desktop.
                bool result = User32.CloseDesktop(_desktopHandle);

                if (result)
                {
                    _desktopHandle = IntPtr.Zero;
                    _desktopName   = String.Empty;
                }

                return(result);
            }

            // no desktop was open, so desktop is closed
            return(true);
        }
Ejemplo n.º 6
0
 public static bool Close(IntPtr desktop)
 {
     return(User32.CloseDesktop(desktop));
 }