is there script for: REFRESH desktop and explorer (xp pro, to .vbs file)

3.3k Views Asked by At

hi, am a novice with excel vb. with a .vbs file attempt, will probably need a working example thanks. (trying to get line spacing to work here..)

i have a .vbs file i paste directly to desktop, to toggle setting for hide file name extensions that does work. It does not refresh the desktop and explorer (on the first click of the file), the same as if set it manually (as below). I need help with the refresh portion.

i have an example of the .vbs file using:

MANUAL SETTING: (of hide extension: gets you 1 free refresh of desktop & explorer)

explorer, tools, options, view, check box for: hide extensions for known file types (that item auto updates both the desktop & the windows explorer).

i would like to incorporate that into my script. same basic idea: my script to a text / .vbs file so i can click in on my desktop (as a toggle, ie 1 click turns it on, the next click turns it off; got that/ it works), i need to add to it to spawn a refresh same as, or equivalent for both: desktop & explorer).

paste the following to a text file (or equivalent that will make same result):

FileExt = "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\HideFileExt"

Set Sh = WScript.CreateObject("WScript.Shell")

St = Sh.RegRead(FileExt)

If St = 1 Then

Sh.RegWrite FileExt, 0, "REG_DWORD"

Else

Sh.RegWrite FileExt, 1, "REG_DWORD"

End If

Sh.SendKeys("{F5}") 

rename the text file to: HIDE EXT.vbs instead of .txt, and pasting it to the desktop.

WHAT NEED:

what i need added to it is the refresh of the desktop & the explorer window(s). same as when making the setting manually. the F5 here does not seem to be working on the first time around. on 2nd click of file, it works to send view to opposite of that for which view "state" is actually in.

2

There are 2 best solutions below

1
On

I was very happy when I managed to discover the problem with this code.

After a long time, I realized that it is necessary to add a "sleep" function to the script before calling F5. That way you won't have a problem and the click will work.

OBS1: Even so, I didn't find the solution to update the desktop. The script only works in the active window. If you start it on the Desktopbackground, it will update all folders and files, else it will only update the open folder.

OBS2: Example of Sleep value -> 1000 = 1s Here is the code:

FileExt = "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\HideFileExt"

Set Sh = WScript.CreateObject("WScript.Shell")

St = Sh.RegRead(FileExt)

If St = 1 Then

Sh.RegWrite FileExt, 0, "REG_DWORD"

wscript.sleep 500

Else

Sh.RegWrite FileExt, 1, "REG_DWORD"

wscript.sleep 500

End If

Sh.SendKeys("{F5}") 

If anyone knows how I send F5 to the Desktop I would appreciate it. Thank you

0
On

Hope this could help:

Instead of

Sh.SendKeys("{F5}") 

Try using:

Sh.run "cmd.exe /c taskkill /f /im explorer.exe && start explorer.exe"

It works fine with me. (I'm using XP and windows server 2003)

I found out that F5 key won't simply work as the same as Desktop, right-click, then click refresh. I referred my code here: http://en.kioskea.net/faq/7789-batch-script-to-automatically-reload-explorer-exe