Show/Hide Desktop Icons with a single click

Copper Contributor

Hello,

 

Is there anything i can do by showing/hinding desktop icons using a hotkey.

I tried different softwares but i encounter some problems that are not on my taste. Maybe i can use powershell. If somebody knows a way please i need some help

 

Thanks!

11 Replies

Hello @lucifer224,

 

If you want to use only hotkey, I believe you need to use third-party software as it seems not possible natively in Windows. Though, you can create a batch script for registry change  HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoDesktop:1

 

I found a PowerShell script, but unfortunately that allows only to show Desktop icons, not hide.

 

I highly recommend you to post to PowerShell community to get more ideas and get this resolved:

 

https://techcommunity.microsoft.com/t5/powershell/ct-p/WindowsPowerShell  

 

Hope this helps!

@lucifer224 

Hi,

I found a way and tested it myself on latest Windows 10

here it is:

Create a Shortcut or Hotkey to Turn the Desktop Icons On or Off (howtogeek.com)

 

  1. Download the tool from the website above
  2. you might have to install this too 
  3. make a shortcut of the file (.exe) on desktop
  4. pin that shortcut to start menu or taskbar depending on your preference
  5. clicking on the icon on taskbar or start menu instantly shows/hides desktop icons
  6. in that website above, it also explains how to assign a hotkey to a shortcut, which is a built-in functionality of Windows.

@lucifer224 

 

Late reply, but I found a solution that can be used with a keybind and doesn't require any downloads or installations.

I'm going to assume you know some basics, and won't need step by step.

If you do need step by step, let me know and I will make one. 

 

Create a .ps1 file call it "ToggleShowDesktopIcons.ps1" and edit it to read:

$source = @"
using System;
using System.Runtime.InteropServices;

namespace DesktopUtility
{
    class Win32Functions
    {
        [DllImport("user32.dll")]
        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
        [DllImport("user32.dll")]
        public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
        [DllImport("user32.dll")]
        public static extern IntPtr GetDesktopWindow();
        [DllImport("user32.dll")]
        public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
    }

    public class Desktop
    {
        public static IntPtr GetHandle()
        {
            IntPtr hDesktopWin = Win32Functions.GetDesktopWindow();
            IntPtr hProgman = Win32Functions.FindWindow("Progman", "Program Manager");
            IntPtr hWorkerW = IntPtr.Zero;

            IntPtr hShellViewWin = Win32Functions.FindWindowEx(hProgman, IntPtr.Zero, "SHELLDLL_DefView", "");
            if (hShellViewWin == IntPtr.Zero)
            {
                do
                {
                    hWorkerW = Win32Functions.FindWindowEx(hDesktopWin, hWorkerW, "WorkerW", "");
                    hShellViewWin = Win32Functions.FindWindowEx(hWorkerW, IntPtr.Zero, "SHELLDLL_DefView", "");
                } while (hShellViewWin == IntPtr.Zero && hWorkerW != null);
            }
            return hShellViewWin;
        }

        public static void ToggleDesktopIcons()
        {
            Win32Functions.SendMessage(Desktop.GetHandle(), 0x0111, (IntPtr)0x7402, (IntPtr)0);
        }
    }
}
"@

Add-Type -TypeDefinition $source

[DesktopUtility.Desktop]::ToggleDesktopIcons()

 

 

Code edited by: @Pyro2k6 

Save Exit.

 

Now create a shortcut of the script (Right click> Send to> Create shortcut desktop) and bind a shortcut key

Restart your PC.

The bind you chose should now toggle show/hide desktop icons.

 

 or just run the .ps1 script.

 

I believe the shotkey bind will only work when the shortcut is on the desktop.

Alternatively:

To hide the shortcut, place it inside:

 

"C:\Users\"Your Username"\AppData\Roaming\Microsoft\Windows\Start 

@NolandC - I wonder why Microsoft haven`t added the hide-icons-feature to the presentation mode settings? 
There you can turn of the screenprotector, chose another background and chose volume level- when it`s turned on - it should have been an option to hide the icons as well.

How do we reach someone that can fix it as a built in Windows feature?

@NolandC hey, i tried the method you described, but i just get a short cmd prompt window with some red text, but cant seem to get it to work? what am i doing wrong?

@Pyro2k6 here's what it says:

Spoiler

source : Die Benennung "source" wurde nicht als Name eines Cmdlet, einer Funktion, einer Skriptdatei oder eines
ausführbaren Programms erkannt. Überprüfen Sie die Schreibweise des Namens, oder ob der Pfad korrekt ist (sofern
enthalten), und wiederholen Sie den Vorgang.
In C:\Curseforge\scripts\ToggleShowDesktopIcons.ps1:1 Zeichen:1
+ source = @'
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (source:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

Add-Type : Das Argument kann nicht an den Parameter "TypeDefinition" gebunden werden, da es NULL ist.
In C:\Curseforge\scripts\ToggleShowDesktopIcons.ps1:46 Zeichen:26
+ Add-Type -TypeDefinition $source
+ ~~~~~~~
+ CategoryInfo : InvalidData: (:) [Add-Type], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddTypeComm
and

Der Typ [DesktopUtility.Desktop] wurde nicht gefunden.
In C:\Curseforge\scripts\ToggleShowDesktopIcons.ps1:48 Zeichen:1
+ [DesktopUtility.Desktop]::ToggleDesktopIcons()
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (DesktopUtility.Desktop:TypeName) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound

@Pyro2k6 

thanks to CHATGPT i made a fixed version of the code:

 

$source = @"
using System;
using System.Runtime.InteropServices;

namespace DesktopUtility
{
    class Win32Functions
    {
        [DllImport("user32.dll")]
        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
        [DllImport("user32.dll")]
        public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
        [DllImport("user32.dll")]
        public static extern IntPtr GetDesktopWindow();
        [DllImport("user32.dll")]
        public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
    }

    public class Desktop
    {
        public static IntPtr GetHandle()
        {
            IntPtr hDesktopWin = Win32Functions.GetDesktopWindow();
            IntPtr hProgman = Win32Functions.FindWindow("Progman", "Program Manager");
            IntPtr hWorkerW = IntPtr.Zero;

            IntPtr hShellViewWin = Win32Functions.FindWindowEx(hProgman, IntPtr.Zero, "SHELLDLL_DefView", "");
            if (hShellViewWin == IntPtr.Zero)
            {
                do
                {
                    hWorkerW = Win32Functions.FindWindowEx(hDesktopWin, hWorkerW, "WorkerW", "");
                    hShellViewWin = Win32Functions.FindWindowEx(hWorkerW, IntPtr.Zero, "SHELLDLL_DefView", "");
                } while (hShellViewWin == IntPtr.Zero && hWorkerW != null);
            }
            return hShellViewWin;
        }

        public static void ToggleDesktopIcons()
        {
            Win32Functions.SendMessage(Desktop.GetHandle(), 0x0111, (IntPtr)0x7402, (IntPtr)0);
        }
    }
}
"@

Add-Type -TypeDefinition $source

[DesktopUtility.Desktop]::ToggleDesktopIcons()
What's the solution?
the turorial and then the code snippet i send

@Pyro2k6  I'm not sure why it wasn't working when you tried maybe an update broke it.. I'll edit the post with your new code. Thanks :) Also the batch file isnt required. You can just make a shortcut of the script and bind a short key to that. 

To execute the script using a hotkey, you can create a shortcut to it and then assign a keyboard shortcut to the shortcut file:

1.Save the PowerShell script in a convenient location.
2.Right-click on the script file and select "Create shortcut".
3.Right-click on the shortcut file and select "Properties".
4.In the "Shortcut" tab, locate the "Shortcut key" field and click on it.
5.Press the desired key combination. For example, you could use Ctrl+Alt+D.
6.Click "Apply" and then "OK" to save the changes.