(OT) Show desktop from command line?

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
#1
A file such as this SHOWDESK.SFC on the desktop will act like Win 7's show desktop button.
Code:
[Shell]
Command=2
IconFile=explorer.exe,3
[TaskBar]
Command=ToggleDesktop
But I can't "execute" that file by name, with START, or with my SHELLEX (ShellExecute) plugin command. Does anyone know how to "show desktop" from a command line?
 

samintz

Scott Mintz
May 20, 2008
1,203
11
Solon, OH, USA
#2
Windows+D key combination will show the desktop.

Other useful ones I use all the time are:
Win+R - Run... Dialog
Win+L - Lock the workstation

There are a bunch more, but I only use those three.

-Scott
 
May 29, 2008
516
3
Groton, CT
#10
It works under Windows XP Pro SP3, too. And I've created a Take Command tool button for it by filling in the Command field with just the name of the .SCF file.
 
#11
Okay, I just tried it in Windows 7 instead of XP, and under Windows 7 it works (i.e. doesn't work) as you describe. Looks like Microsoft broke it!
It's easy enough to do simulating Win-D (I don't have a Win key, code below).
Perhaps Rex will consider adding the Win key to the modifiers recognized by KEYSTACK (in a future version of course).
I could put it in, say, the SYSUTILS plugin. Anyone interested?

Code:
{
    INPUT i[4] = {{INPUT_KEYBOARD,0}, {INPUT_KEYBOARD,0}, {INPUT_KEYBOARD,0}, {INPUT_KEYBOARD,0}};
    i[0].ki.wVk = i[3].ki.wVk = VK_LWIN;
    i[1].ki.wVk = i[2].ki.wVk = 'D';
    i[2].ki.dwFlags = i[3].ki.dwFlags = KEYEVENTF_KEYUP;
    SendInput(4, i, sizeof(INPUT));
    return 0;
}
 
#13
Is this a possible solution? I've tried it in XP, and it works;

Minimize all;
Code:
set shelltray=%@winapi[user32,FindWindow,"Shell_TrayWnd",0]
echo %@winapi[user32,PostMessage,%shelltray,273,419]
Minimize undo;
Code:
set shelltray=%@winapi[user32,FindWindow,"Shell_TrayWnd",0]
echo %@winapi[user32,PostMessage,%shelltray,273,416]
Joe
 
#14
Is this a possible solution? I've tried it in XP, and it works;

Minimize all;
Code:
set shelltray=%@winapi[user32,FindWindow,"Shell_TrayWnd",0]
echo %@winapi[user32,PostMessage,%shelltray,273,419]
Minimize undo;
Code:
set shelltray=%@winapi[user32,FindWindow,"Shell_TrayWnd",0]
echo %@winapi[user32,PostMessage,%shelltray,273,416]
Joe
Hmmm! It sort of works. After minimizing all that way, clicking Win7's "show desktop" button doesn't bring everything back (especially TCC itself).
 
#15
I've added a MINIMIZEALL to UIStuff:
unm.edu/~cdye/plugins/uistuff.html#minimizeall

It uses the shell's COM interface instead of simulating keystrokes, so it may behave differently from yours....
Did you find any quirks? The code I posted, built into an EXE (console or windows) does something very strange. After using it to show the desktop, and either running it again or clicking Win7's button to bring things back, the console in which I gave the command (TCC or CMD) is almost certain ***not*** to have a cursor and although it will accept (some) input, "Enter" does nothing but play the BEEP OK sound.
 
#16
I've added a MINIMIZEALL to UIStuff:
unm.edu/~cdye/plugins/uistuff.html#minimizeall

It uses the shell's COM interface instead of simulating keystrokes, so it may behave differently from yours....
One thing different is that it doesn't get all the windows that the Win7 ShowDesktop button (or my simulation of Win-D) does. It misses my PowerPro windows. They may be different in that they have WS_POPUP and WS_EX_TOOLWINDOW.

I tried again with a simulated click (SendInput again) on Win7's ShowDesktop button. That seems to work as well as the button itself. But the button itself is a bit quirky. First, it doesn't always restore windows in the same Z-order (i.e., TCC may be on top of DevStudio before ShowDesktop/Restore and inder it later). Second, when the desktop is restored with a second click, keyboard focus is not restored. And here's a good one ... third ... click Win7's ShowDesktop button **four** times **without moving the mouse in between** (easy with a trackball) ... then press Enter ... here, that causes the StartMenu to open! I've Googled accounts of the ShowDesktop button leaving some windows "always on top" (haven't seen it myself).
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,376
39
Albuquerque, NM
prospero.unm.edu
#17
Did you find any quirks? The code I posted, built into an EXE (console or windows) does something very strange. After using it to show the desktop, and either running it again or clicking Win7's button to bring things back, the console in which I gave the command (TCC or CMD) is almost certain ***not*** to have a cursor and although it will accept (some) input, "Enter" does nothing but play the BEEP OK sound.
I've seen that once or twice while pressing Win-D -- pushing the actual physical keys with my fingers. Perhaps the funky keystroke is confusing the console? Is it possible that Microsoft has never updated the console handler to recognize their very own keys? I have not seen that effect with the shell API approach, but then I haven't tested it much.
 
#18
I've seen that once or twice while pressing Win-D -- pushing the actual physical keys with my fingers. Perhaps the funky keystroke is confusing the console? Is it possible that Microsoft has never updated the console handler to recognize their very own keys? I have not seen that effect with the shell API approach, but then I haven't tested it much.
I'd expect that neither the console nor conhost.exe even see a keystroke such as Win-D.
 
Nov 18, 2009
17
0
#19
If you can create a vbscript file, create a file (named "ShowDesktop.vbs") containing:
CreateObject("Shell.Application").ToggleDesktop
and launch it with cscript //B ShowDesktop.vbs

If you have more patience, you can also do a PowerShell command line:
powershell (new-object -comobject "Shell.Application").ToggleDesktop()

But powershell takes a lot longer than cscript to launch.

You could also use the TCC TASKBAR MIN command, though interestingly it only seems to do the first monitor, so it probably doesn't call Shell32.IShellDispatch4.ToggleDesktop.
 
#20
Well I really wanted an EXE, so I suppose cscript will work. In yet another attempt, I used the code below, which seems to work just like the Win7 button. Setting the foreground window to the desktop first gets rid of a restored console often not having a cursor and accepting onle some input ... no loss since in my experience, restoring with the ShowDesktop button doesn't give anything input focus.
Code:
    HWND hWnd[3];
    if    (
            (hWnd[0] = FindWindow(L"Shell_TrayWnd", L"")) != NULL
            &&
            (hWnd[1] = FindWindowEx(hWnd[0], NULL, L"TrayNotifyWnd", L"")) != NULL
            &&
            (hWnd[2] = FindWindowEx(hWnd[1], NULL, L"TrayShowDesktopButtonWClass", NULL)) != NULL
        )
    {
        SetForegroundWindow(GetDesktopWindow());
        SendMessage(hWnd[2], WM_LBUTTONDOWN, 0, 0);
        SendMessage(hWnd[2], WM_LBUTTONUP, 0, 0);
    }