Rem: Clearing the Windows Desktop

Do you have a scripting-related question or problem? You can send your question or problem to [email protected]

How can I make my scripts clear the Windows desktop when they start to run?

To clear the Windows desktop manually, you typically press the Windows logo key and the M key simultaneously. Unfortunately, you can't programmatically send this key combination to the Windows shell or any other application. Although the Windows logo key has a key code (i.e., a unique code number identifying that key), Windows Script Host's (WSH's) WshShell.SendKey method doesn't support that key code.

However, you can use the Shell.Application object. This COM object is natively available with any version of Windows 98 and newer Windows OSs, including Windows XP and Windows 2000. The Shell.Application object isn't a native part of Windows NT 4.0, but you can obtain and use the object by installing Microsoft Internet Explorer (IE) 4.0 or later.

To clear the desktop, you can use the Shell.Application object's MinimizeAll method to minimize all currently opened windows. You need to create an instance of the object, then call the MinimizeAll method with code such as

Set shellOM = _
  CreateObject("Shell.Application")
shellOM.MinimizeAll

If you place this code at the beginning of the script, you'll clear the desktop before the rest of the script runs. To restore the windows back to their original size, you add the code

shellOM.UndoMinimizeALL

at the end of the script. Note that MinimizeAll and UndoMinimizeALL are case sensitive.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish