1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

(OT) Show desktop from command line?

Discussion in 'Support' started by vefatica, Jun 28, 2012.

  1. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,784
    Likes Received:
    29
    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?
     
  2. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,177
    Likes Received:
    11
    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
     
  3. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,277
    Likes Received:
    38
    Shouldn't that extension be .SCF ?
     
  4. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,784
    Likes Received:
    29
    Yes (typo).
     
  5. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,277
    Likes Received:
    38
    Running it with START works here.
     
  6. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,784
    Likes Received:
    29
    Not here. "Start showdesk.scf" causes a second instance of explorer.exe to start and does *not* show the desktop.
     
  7. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,277
    Likes Received:
    38
    Code:
    C:\>ftype %@assoc[.scf]
    SHCmdFile=explorer.exe
     
    C:\>
    
     
  8. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,784
    Likes Received:
    29
    I get the same:
    Code:
    v:\> ftype %@assoc[.scf]
    SHCmdFile=C:\Windows\explorer.exe
     
  9. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,277
    Likes Received:
    38
    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!
     
  10. dcantor

    Joined:
    May 29, 2008
    Messages:
    505
    Likes Received:
    3
    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. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,784
    Likes Received:
    29
    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;
    }
     
  12. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,277
    Likes Received:
    38
    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....
     
    #12 Charles Dye, Jun 28, 2012
    Last edited by a moderator: May 25, 2017
  13. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    638
    Likes Received:
    6
    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. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,784
    Likes Received:
    29
    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. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,784
    Likes Received:
    29
    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. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,784
    Likes Received:
    29
    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).
     
  17. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,277
    Likes Received:
    38
    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. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,784
    Likes Received:
    29
    I'd expect that neither the console nor conhost.exe even see a keystroke such as Win-D.
     
  19. NetMage

    Joined:
    Nov 18, 2009
    Messages:
    17
    Likes Received:
    0
    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. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,784
    Likes Received:
    29
    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);
        }
    
     

Share This Page