public Desktop(string name) { // make sure desktop doesnt already exist. if (Exists(name)) { // open the desktop. DesktopHandle = User32.OpenDesktop(name, 0, true, DesktopAccessRights.AllRights); // something went wrong. if (DesktopHandle == IntPtr.Zero) { throw new Exception(); } return; } // attempt to create desktop. DesktopHandle = User32.CreateDesktop(name, IntPtr.Zero, IntPtr.Zero, 0, DesktopAccessRights.AllRights, IntPtr.Zero); // something went wrong. if (DesktopHandle == IntPtr.Zero) { throw new Exception(); } }
/// <summary> /// Creates a new desktop. If a handle is open, it will be closed. /// </summary> /// <param name="name">The name of the new desktop. Must be unique, and is case sensitive.</param> /// <returns>True if desktop was successfully created, otherwise false.</returns> public bool Create(string name) { // make sure object isnt disposed CheckDisposed(); // close the open desktop if (_desktopHandle != IntPtr.Zero) { // attempt to close the desktop if (!Close()) { return(false); } } User32.OpenInputDesktop(0, false, WinBase.ACCESS_MASK.DESKTOP_SWITCHDESKTOP); // make sure desktop doesnt already exist if (Exists(name)) { // it exists, so open it return(Open(name)); } // attempt to create desktop _desktopHandle = User32.CreateDesktop(name, IntPtr.Zero, IntPtr.Zero, 0, AccessRights, IntPtr.Zero); _desktopName = name; return(_desktopHandle != IntPtr.Zero); }
///<summary> /// Creates a new desktop with the given name, and conditionally displays it. ///</summary> ///<param name="name">The name of the new desktop.</param> ///<param name="display">True if the new desktop should be displayed.</param> public Desktop(string name, bool display) { shouldDisplayDesktop = display; realDesktopHandle = CurrentHandle(); testDesktopHandle = User32.CreateDesktop(name, IntPtr.Zero, IntPtr.Zero, 0, Win32.GENERIC_ALL, IntPtr.Zero); User32.SetThreadDesktop(testDesktopHandle); Switch(shouldDisplayDesktop); }
public static IntPtr Create(string name) { return(User32.CreateDesktop(name, IntPtr.Zero, IntPtr.Zero, 0, (int)DesktopAccessMask.GenericAll, IntPtr.Zero)); }
private IntPtr createNewDesktop() => User32.CreateDesktop(Name, IntPtr.Zero, IntPtr.Zero, 0, (long)DesktopAcessMask.GENERIC_ALL, IntPtr.Zero);