• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1018
  • Last Modified:

Force Registry to update

I have a program in which I want a button to toggle on/off the showing of hidden files/folders.

I know to do this I just need change the value of:

HKCU\Software\Microsoft\windows\currentversion\Explorer\Advanced\Hidden

If an open folder has hidden files/folders the hidden files/folders do not disappear/appear until I choose View->Refresh or press F5.

Is there a way that I can make it programatically refresh?
0
moterk
Asked:
moterk
  • 4
  • 3
  • 3
  • +5
1 Solution
 
iozturkCommented:
set WshShell = WScript.CreateObject ("WScript.Shell")

WshShell.RegWrite ("HKCU\\Software\\ACME\\FortuneTeller\\", 1, "REG_BINARY")
WshShell.RegWrite ("HKCU\\Software\\ACME\\FortuneTeller\\MindReader", "Goocher!", "REG_SZ")

set bKey =    WshShell.RegRead ("HKCU\\Software\\ACME\\FortuneTeller\\")
WScript.Echo (WshShell.RegRead ("HKCU\\Software\\ACME\\FortuneTeller\\MindReader"))

WshShell.RegDelete ("HKCU\\Software\\ACME\\FortuneTeller\\MindReader")
WshShell.RegDelete ("HKCU\\Software\\ACME\\FortuneTeller\\")
WshShell.RegDelete ("HKCU\\Software\\ACME\\")
0
 
iozturkCommented:
So sory, I copy and paste from jscript the code should look like

Dim WshShell

Set WshShell = CreateObject("WScript.Shell")

WshShell.RegWrite "HKCU\Software\ACME\FortuneTeller\", 1, "REG_BINARY"
WshShell.RegWrite "HKCU\Software\ACME\FortuneTeller\MindReader", "Goocher!", "REG_SZ"

bkey = WshShell.RegRead("HKCU\Software\ACME\FortuneTeller\")
MsgBox WshShell.RegRead("HKCU\Software\ACME\FortuneTeller\MindReader")

WshShell.RegDelete ("HKCU\Software\ACME\FortuneTeller\MindReader")
WshShell.RegDelete ("HKCU\Software\ACME\FortuneTeller\")
WshShell.RegDelete ("HKCU\Software\ACME\")

0
 
iozturkCommented:
If you want this code run on WinNT 4 windows scripting host should be installed otherwise you should use windows API's.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
moterkAuthor Commented:
I am sorry iozturk but I do not see what you comment has to do with my question "Is there a way that I can make it programatically refresh?"
0
 
Richie_SimonettiIT OperationsCommented:
Maybe you need this too (after do the change to registry)

private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
private Const HWND_BROADCAST = &HFFFF&
private Const WM_WININICHANGE = &H1A


Public Sub Anounce_locale_change()
PostMessage HWND_BROADCAST, WM_WININICHANGE, 0, 0
End Sub
0
 
moterkAuthor Commented:
I had already tried:

SendMessage HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0

Now because of Richie's suggestion I tried

PostMessage HWND_BROADCAST, WM_WININICHANGE, 0, 0
SendMessage HWND_BROADCAST, WM_WININICHANGE, 0, 0
PostMessage HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0

None of these work either.
0
 
Richie_SimonettiIT OperationsCommented:
Are you working with XP?
Also, take in mind that Explorer.exe re-scan the folder to show them again with new attributes.
0
 
moterkAuthor Commented:
Yes I am working with XP but I would like it to work with older Windows OS as well (if possible).

What do you mean by "take in mind that Explorer.exe re-scan the folder to show them again with new attributes"

I know I can do a View->Refresh or press F5 in explorer but I want the refresh to be automatic, so that my program's user can see that something happened.
0
 
Richie_SimonettiIT OperationsCommented:
I meant, even explorer.exe re-scan the folder to refresh the view with new folders attributes (maybe don't you see it but it is what it does).
So, taking this in mind, you could use a dirty/cheap solution.
Locate explorer window and do:
sendkeys "{F5}"
0
 
moterkAuthor Commented:
There may not be an open explorer window.  But if they have hidden files or folders on the desktop they should show up or disappear as soon as the user clicks the "Show" or the "Hide" button.

0
 
CleanupPingCommented:
moterk:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0
 
Kalimac55Commented:
You have to use SendMessage and not PostMessage! The below code works fine for me..

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const HWND_BROADCAST = &HFFFF&
Private Const WM_SETTINGCHANGE = &H1A


SendMessage HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0

In case you are still interested.
0
 
Kalimac55Commented:
And of course a more decent test proved that did not work either. Sorry.
0
 
scottzzCommented:

moterk - do you still need help with this?

I have it working in VB, but need to polish it up before posting.  

Let me know,
-Scott

0
 
GPrentice00Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

 -->Split between Richie_Simonetti and Kalimac55

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER

GPrentice00
Cleanup Volunteer
0
 
GPrentice00Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

 -->PAQ - no points refunded

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER

GPrentice00
Cleanup Volunteer
0
 
YensidModCommented:
This question is PAQed and no points refunded (of 500)

YensidMod
Expert Exchange Moderator
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 4
  • 3
  • 3
  • +5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now