Sign in to follow this  
Followers 0
BlindWolf8

I can't refresh the desktop after registry changes

10 posts in this topic

#1 ·  Posted (edited)

Hey guys,

I'm making a program to change up some system settings that I normally change when I go to client's computers. I really can't get the Desktop/taskbar to refresh without a logoff/logon, and the code:

RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters ,1 ,True

...doesn't work! I am using XP with Service Pack 2b in VMWare 6.0 for testing.

Here is the code I have so far:

CODE

#cs ----------------------------------------------------------------------------

AutoIt Version: 3.2.4.9

Author: Dan Fischbach

Script Function:

Edit some system settings.

Script Copyright:

This work is licensed under the

Creative Commons Attribution-Noncommercial-Share Alike 3.0 License.

To view a copy of this license, visit

http://creativecommons.org/licenses/by-nc-sa/3.0/

or send a letter to:

Creative Commons

171 Second Street, Suite 300

San Francisco, California, 94105, USA

#ce ----------------------------------------------------------------------------

;-- Script options -------------------------------------------------------------

Opt("GUICloseOnESC", 0) ;Do not close when ESC is pressed

Opt("GUIOnEventMode", 1) ;Do events on actions

Opt("TrayIconDebug", 1) ;Show debug info in tray icon tooltip

Opt("TrayIconHide", 0) ;Show tray icon

Opt("RunErrorsFatal", 1) ;Always show fatal errors

;-- Script Includes -------------------------------------------------------------

#include <GUIConstants.au3>

;-- GUI time --------------------------------------------------------------------

$mainwindow = GUICreate("EasySet", 175, 280, -1, -1)

GUISetOnEvent($GUI_EVENT_CLOSE, "FN_EXIT")

GUICtrlCreateLabel("Edit some Windows settings/files:", 10, 10)

$CB_HF = GUICtrlCreateCheckbox ("Show hidden files", 10, 30, 150, 20)

GUICtrlSetOnEvent($CB_HF, "FN_HF")

$CB_CT = GUICtrlCreateCheckbox ("Do not cache thumbnails", 10, 50, 150, 20)

GUICtrlSetOnEvent($CB_CT, "FN_CT")

$CB_SD = GUICtrlCreateCheckbox ("Show inside system folders", 10, 70, 150, 20)

GUICtrlSetOnEvent($CB_SD, "FN_SD")

$CB_EX = GUICtrlCreateCheckbox ("Show all file extensions", 10, 90, 150, 20)

GUICtrlSetOnEvent($CB_EX, "FN_EX")

$CB_SF = GUICtrlCreateCheckbox ("Show hidden system files", 10, 110, 150, 20)

GUICtrlSetOnEvent($CB_SF, "FN_SF")

$CB_CC = GUICtrlCreateCheckbox ("Use classic Control Panel", 10, 130, 150, 20)

GUICtrlSetOnEvent($CB_CC, "FN_CC")

$CB_GR = GUICtrlCreateCheckbox ("Don't group taskbar buttons", 10, 150, 150, 20)

GUICtrlSetOnEvent($CB_GR, "FN_GR")

$CB_IA = GUICtrlCreateCheckbox ("Don't hide inactive icons", 10, 170, 150, 20)

GUICtrlSetOnEvent($CB_IA, "FN_IA")

$CB_PR = GUICtrlCreateCheckbox ("Don't use fade/slide effects", 10, 190, 150, 20)

GUICtrlSetOnEvent($CB_PR, "FN_PR")

$CB_DD = GUICtrlCreateCheckbox ("Delete WU/MU temp files", 10, 210, 150, 20)

GUICtrlSetOnEvent($CB_DD, "FN_DD")

$BN_X = GUICtrlCreateButton("Close", 55, 240, 60, -1)

GUICtrlSetOnEvent($BN_X, "FN_EXIT")

;-- Read current settings from registry and check/uncheck accordingly

;-- Read current "Show hidden files" setting

$read = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "Hidden")

If $read == 2 Then

GUICtrlSetState ($CB_HF, $GUI_UNCHECKED)

Else

GUICtrlSetState ($CB_HF, $GUI_CHECKED)

EndIf

;-- Read current "Do not cache thumbnails" setting

$read = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "DisableThumbnailCache")

If $read == 0 OR $read == "" Then

GUICtrlSetState ($CB_CT, $GUI_UNCHECKED)

Else

GUICtrlSetState ($CB_CT, $GUI_CHECKED)

EndIf

;-- Read current "Show inside system folders" setting

$read = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "WebViewBarricade")

If $read == 0 OR $read == "" Then

GUICtrlSetState ($CB_SD, $GUI_UNCHECKED)

Else

GUICtrlSetState ($CB_SD, $GUI_CHECKED)

EndIf

;-- Read current "Show all file extensions" setting

$read = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "HideFileExt")

If $read == 1 Then

GUICtrlSetState ($CB_EX, $GUI_UNCHECKED)

Else

GUICtrlSetState ($CB_EX, $GUI_CHECKED)

EndIf

;-- Read current "Show hidden system files" setting

$read = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "ShowSuperHidden")

If $read == 0 OR $read == "" Then

GUICtrlSetState ($CB_SF, $GUI_UNCHECKED)

Else

GUICtrlSetState ($CB_SF, $GUI_CHECKED)

EndIf

;-- Read current "Use classic Control Panel" setting

$read = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\WebView\BarricadedFolders", "shell:ControlPanelFolder")

If $read == 1 Then

GUICtrlSetState ($CB_CC, $GUI_UNCHECKED)

Else

GUICtrlSetState ($CB_CC, $GUI_CHECKED)

EndIf

;-- Read current "Don't group taskbar buttons" setting

$read = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "TaskbarGlomming")

If $read == 1 OR $read == "" Then

GUICtrlSetState ($CB_GR, $GUI_UNCHECKED)

Else

GUICtrlSetState ($CB_GR, $GUI_CHECKED)

EndIf

;-- Read current "Don't hide inactive icons" setting

$read = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer", "EnableAutoTray")

If $read == 1 OR $read == "" Then

GUICtrlSetState ($CB_IA, $GUI_UNCHECKED)

Else

GUICtrlSetState ($CB_IA, $GUI_CHECKED)

EndIf

;-- Read current "Don't use fade/slide effects" setting

$read = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\VisualEffects", "VisualFXSetting")

If $read == 1 OR $read == "" Then

GUICtrlSetState ($CB_PR, $GUI_UNCHECKED)

Else

GUICtrlSetState ($CB_PR, $GUI_CHECKED)

EndIf

;-- Find WU/MU temp files to delete, if any and set setting accordingly

$dir = @WindowsDir & "\"

$SS_WUFILES = FileFindFirstFile($dir & "KB*.log")

$SS_WUFOLDERS = FileFindFirstFile($dir & "$NtUninstallKB*" & "$")

$SS_WUFX = FileFindFirstFile($dir & "$MSI31Uninstall_KB893803v2$")

If $SS_WUFILES == -1 AND $SS_WUFOLDERS == -1 AND $SS_WUFX == -1 Then

GUICtrlSetState ($CB_DD, $GUI_CHECKED)

GUICtrlSetState ($CB_DD, $GUI_DISABLE)

Else

GUICtrlSetState ($CB_DD, $GUI_UNCHECKED)

GUICtrlSetState ($CB_DD, $GUI_ENABLE)

EndIf

GUISetState(@SW_SHOW) ;When we're ready, lift the curtain!

While 1

Sleep(60000) ;Just screw around while other, more important shit is done

; :-)

WEnd

;-- Functions -------------------------------------------------------------------

Func FN_HF()

If BitAnd(GUICtrlRead($CB_HF),$GUI_UNCHECKED) Then

RegWrite ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "Hidden", "REG_DWORD", "0x00000002")

Else

RegWrite ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "Hidden", "REG_DWORD", "0x00000001")

EndIf

REFRESH()

EndFunc

Func FN_CT()

If BitAnd(GUICtrlRead($CB_CT),$GUI_UNCHECKED) Then

RegWrite ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "DisableThumbnailCache", "REG_DWORD", "0x00000000")

Else

RegWrite ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "DisableThumbnailCache", "REG_DWORD", "0x00000001")

EndIf

REFRESH()

EndFunc

Func FN_SD()

If BitAnd(GUICtrlRead($CB_SD),$GUI_UNCHECKED) Then

RegWrite ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "WebViewBarricade", "REG_DWORD", "0x00000000")

Else

RegWrite ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "WebViewBarricade", "REG_DWORD", "0x00000001")

EndIf

REFRESH()

EndFunc

Func FN_EX()

If BitAnd(GUICtrlRead($CB_EX),$GUI_UNCHECKED) Then

RegWrite ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "HideFileExt", "REG_DWORD", "0x00000001")

Else

RegWrite ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "HideFileExt", "REG_DWORD", "0x00000000")

EndIf

REFRESH()

EndFunc

Func FN_SF()

If BitAnd(GUICtrlRead($CB_SF),$GUI_UNCHECKED) Then

RegWrite ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "ShowSuperHidden", "REG_DWORD", "0x00000000")

Else

RegWrite ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "ShowSuperHidden", "REG_DWORD", "0x00000001")

EndIf

REFRESH()

EndFunc

Func FN_CC()

If BitAnd(GUICtrlRead($CB_CC),$GUI_UNCHECKED) Then

RegWrite ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\WebView\BarricadedFolders", "shell:ControlPanelFolder", "REG_DWORD", "0x00000001")

Else

RegWrite ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\WebView\BarricadedFolders", "shell:ControlPanelFolder", "REG_DWORD", "0x00000000")

EndIf

REFRESH()

EndFunc

Func FN_GR()

If BitAnd(GUICtrlRead($CB_GR),$GUI_UNCHECKED) Then

RegWrite ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "TaskbarGlomming", "REG_DWORD", "0x00000001")

Else

RegWrite ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "TaskbarGlomming", "REG_DWORD", "0x00000000")

EndIf

REFRESH()

EndFunc

Func FN_IA()

If BitAnd(GUICtrlRead($CB_IA),$GUI_UNCHECKED) Then

RegWrite ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer", "EnableAutoTray", "REG_DWORD", "0x00000001")

Else

RegWrite ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer", "EnableAutoTray", "REG_DWORD", "0x00000000")

EndIf

REFRESH()

EndFunc

Func FN_PR()

If BitAnd(GUICtrlRead($CB_PR),$GUI_UNCHECKED) Then

RegWrite ("HKEY_CURRENT_USER\Control Panel\Desktop", "UserPreferencesMask", "REG_BINARY", "9E3E0780")

RegWrite ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "ListviewWatermark", "REG_DWORD", "0x00000001")

RegWrite ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "TaskbarAnimations", "REG_DWORD", "0x00000001")

RegWrite ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\VisualEffects", "VisualFXSetting", "REG_DWORD", "0x00000001")

Else

RegWrite ("HKEY_CURRENT_USER\Control Panel\Desktop", "UserPreferencesMask", "REG_BINARY", "90320780")

RegWrite ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "ListviewWatermark", "REG_DWORD", "0x00000000")

RegWrite ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "TaskbarAnimations", "REG_DWORD", "0x00000000")

RegWrite ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\VisualEffects", "VisualFXSetting", "REG_DWORD", "0x00000003")

EndIf

REFRESH()

EndFunc

Func FN_DD()

ProgressOn ("Deleting WU/MU temp files", "Deleting WU/MU temp files")

ProgressSet (33)

;Keeps looping until the error flag is 1

$nextfile = FileFindNextFile($SS_WUFILES)

While @error <> 1

FileDelete($dir & $nextfile)

$nextfile = FileFindNextFile($SS_WUFILES)

WEnd

FileClose($SS_WUFILES)

ProgressSet (66)

;Keeps looping until the error flag is 1

$nextfile = FileFindNextFile($SS_WUFOLDERS)

While @error <> 1

DirRemove($dir & $nextfile, 1)

$nextfile = FileFindNextFile($SS_WUFOLDERS)

WEnd

FileClose($SS_WUFOLDERS)

ProgressSet (100)

;Keeps looping until the error flag is 1

$nextfile = FileFindNextFile($SS_WUFX)

While @error <> 1

DirRemove($dir & $nextfile, 1)

$nextfile = FileFindNextFile($SS_WUFX)

WEnd

FileClose($SS_WUFX)

;Since everything's gone, let's lock it up

GUICtrlSetState ($CB_DD, $GUI_DISABLE)

ProgressOff()

REFRESH()

EndFunc

Func REFRESH()

Run("RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters ,1 ,True")

EndFunc

Func FN_EXIT()

;With some luck, this command should refresh explorer without having to

;log off/on or restart Windows. Sweet!

REFRESH()

;Credits: Pete Smith.

;Batch files - RUNDLL and RUNDLL32

;http://www.robvanderwoude.com/rundll.html

;End of the road

Exit

EndFunc

Any suggestions as to what to do to avoid a logon/logoff would be greatly appreciated. Thanks again!

Edited by BlindWolf8

Share this post


Link to post
Share on other sites



Hi,

Try functions here (UpdateExplorer()).


 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

Hi,

Try functions here (UpdateExplorer()).

Hmmmm...why have other people gotten the code I posted above to work and I cannot? There's a post from around 2005 when that call worked. I'll keep your functions in mind if all else fails. Thanks!

Share this post


Link to post
Share on other sites

Would closing and rerunning Explorer.exe work?

Func _Refresh()
    Local $process = "explorer.exe"
    Do
        ProcessClose($process)
    Until Not ProcessExists($process)
    Run($process)
EndFunc
Nope, that's sort of messy. Here's the old AutoIt thread I didn't want to post in as it's really old. No one really found a solution back then.

Share this post


Link to post
Share on other sites

closing and reopening explorer.exe does work but it makes the menu bar disappear and reappear and for me it opens my documents at the end not sure why. Does it do that for any one else?

Share this post


Link to post
Share on other sites

Remove the "Run($process)"

It shouldn't bring My Documents up now.

Share this post


Link to post
Share on other sites

No one's found a solution to this problem? Did anyone check that old thread that I linked to?

Share this post


Link to post
Share on other sites

killing explorer.exe and rerunning it isn't messy your a newb for that...

Share this post


Link to post
Share on other sites

killing explorer.exe and rerunning it isn't messy your a newb for that...

It's not? A lot of times it won't refresh the tray icons that were in place. Show some respect. Maybe you don't understand the inconvenience of having to "restart" things:

What if you had to restart your car to turn the headlights on?

Think back to Windows 98 when you had to restart to install any driver and almost every program.

1 person likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0