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

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


0
3/15/2010 5:02:27 PM
scripting.vbscript 564 articles. 0 followers. Follow

2 Replies
2080 Views

Similar Articles

[PageSpeed] 11

<-> wrote in message news:OxurLFGxKHA.3408@TK2MSFTNGP06.phx.gbl...
> 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

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. 

0
Pegasus
3/15/2010 5:13:33 PM
On Mar 15, 12:02=A0pm, <-> wrote:
> 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. =A0A=
ll
> these scripts can't be wrong. =A0It just simply doesn't refresh the deskt=
op.
> I'm doing the Outlook desktop icon thing and if this doesn't work i'm goi=
ng
> 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 ad=
d?
> I've tried two scripts that utilize the sendkeys function, and neither wo=
rk.
> They don't give an error they just simply don't work. =A0What is missing?
>
> here is a sample of one of the scripts I used:
>
> Option Explicit
> Dim WSHShell, strDesktop
> Set WSHShell =3D WScript.CreateObject("WScript.Shell")
> strDesktop =3D WSHShell.SpecialFolders("Desktop")
> WSHShell.AppActivate strDesktop
> WSHShell.SendKeys "{F5}"
> WScript.Quit

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

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

Or, in JScript:
------------------------------------------
var oShell =3D new ActiveXObject("WScript.shell");
oShell.Run("%windir%\\System32\\RUNDLL32.EXE
user32.dll,UpdatePerUserSystemParameters",1,true);
------------------------------------------
0
TNO
3/15/2010 10:03:07 PM
Reply:

Similar Artilces:

WSHShell.SendKeys "{F5}"
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 fun...