Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

(OT) Show desktop from command line?

May
12,846
164
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?
 
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
 
Not here. "Start showdesk.scf" causes a second instance of explorer.exe to start and does *not* show the desktop.

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 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.
 
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;
}
 
I could put it in, say, the SYSUTILS plugin. Anyone interested?

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....
 
Last edited by a moderator:
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
 
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).
 
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.
 
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).
 
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.
 
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.
 
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.
 
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);
    }
 
run the following:

explorer.exe shell:::{3080F90D-D7AD-11D9-BD98-0000947B0257}

thats the command to show desktop

theres much more

:D
 

Similar threads

Back
Top