Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WSHShell.SendKeys "{F5}" - doesn't work

798 views
Skip to first unread message

-

unread,
Mar 15, 2010, 1:02:27 PM3/15/10
to
I've been trying with every sample script I can find on the Net, but the
double clicking the VBS just flashes the hourglass and then nothing. All
these scripts can't be wrong. It just simply doesn't refresh the desktop.
I'm doing the Outlook desktop icon thing and if this doesn't work i'm going
to have to create the less desirable shortcut to .exe because if the icon
isn't visible immediately then there's no point.

Is there an .EXE utility, or some additional line in the VBS I need to add?
I've tried two scripts that utilize the sendkeys function, and neither work.
They don't give an error they just simply don't work. What is missing?


here is a sample of one of the scripts I used:


Option Explicit
Dim WSHShell, strDesktop
Set WSHShell = WScript.CreateObject("WScript.Shell")
strDesktop = WSHShell.SpecialFolders("Desktop")
WSHShell.AppActivate strDesktop
WSHShell.SendKeys "{F5}"
WScript.Quit


Pegasus [MVP]

unread,
Mar 15, 2010, 1:13:33 PM3/15/10
to
<-> wrote in message news:OxurLFGx...@TK2MSFTNGP06.phx.gbl...

Your program is a macro program and, like all macro programs, it is fragile.
You can never be sure that the keystrokes are issued in the right context
and any number of conditions can disturb your plans.

In your case the code most likely fails to work because you're issuing the
F5 keystroke in a different context than the one you're thinking. Preceding
F5 with Alt+Tab might help. However, you might also find that the behaviour
of Alt+Tab is slightly different under Windows 7 than under WinXP. Just
because your macro works fine under WinXP does not mean that it will work
under Windows 7. As I said, macros are fragile and must be avoided if you
want a robust environment.

-TNO-

unread,
Mar 15, 2010, 6:03:07 PM3/15/10
to

If you wish to refresh the desktop, use the following instead since
SendKeys can "miss":

VBS:
------------------------------------------
Dim oShell : Set oShell = CreateObject("WScript.shell")
oShell.Run "%windir%\System32\RUNDLL32.EXE
user32.dll,UpdatePerUserSystemParameters",1,True
------------------------------------------

Or, in JScript:
------------------------------------------
var oShell = new ActiveXObject("WScript.shell");
oShell.Run("%windir%\\System32\\RUNDLL32.EXE
user32.dll,UpdatePerUserSystemParameters",1,true);
------------------------------------------

0 new messages