Jump to content

Activate registry settings without logging off


Recommended Posts

I have always wanted a way of configuring Windows Explorer to my preferred settings when I log on. I was never able to do it with VBscript without requiring a logoff/logon so I gave up. When I found AutoIT I figured this would be a good time to try again.

This script works fine if you run it manually. It will make all the custom changes by applying the registry settings then it opens Folder Options, clicks "Apply to All Folders" then clicks OK.

The problem is trying to get it to work in a login script. All the registry settings are applied fine but, with it running in a login script, Explorer hasn't had the chance to fully start. So, it fails to apply the settings and a logoff/logon is required.

Does anyone know how to apply the registry changes that effect Folder Options similar to "RunWait("rundll32 user32.dll,UpdatePerUserSystemParameters")"? I Googled to see if some other part of user32.dll could do this but I've come up empty. I thought about killing and restarting Explorer.exe but that can cause big problems with other logon scripts.

This script makes the following changes:

In Folder Options:

Enable "Show hidden files and folders"

Disable "Hide extensions for known file types"

Disable "Hide protected operating system files"

Enable "Display the full path in the title bar"

Enable "Display the full path in the address bar"

Disable "Use simple file sharing"

Enable Windows Explorer Status Bar

Then apply the previous settings to all views

Taskbar and Start Menu Properties:

Disable "Group similar taskbar buttons"

Display Properties:

Display My Documents, My Computer My Network Places and IE icons on Desktop

Misc (reg hack)

Disable search assistant

; Close all Explorer windows before starting
Opt("WinTitleMatchMode", 4)
While WinExists("classname=ExploreWClass", "")
   WinKill("classname=ExploreWClass", "")
WEnd

; Set registry settings that would normally be changed using the GUI
$regvar = "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
RegWrite($regvar, "Hidden", "REG_DWORD", "1")           ; Enable "Show hidden files and folders"
RegWrite($regvar, "HideFileExt", "REG_DWORD", "0")      ; Disable "Hide extensions for known file types"
RegWrite($regvar, "ShowSuperHidden", "REG_DWORD", "1")  ; Disable "Hide protected operating system files"
RegWrite($regvar, "TaskbarGlomming", "REG_DWORD", "0")  ; Disable "Group similar taskbar buttons"

$regvar = "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\CabinetState"
RegWrite($regvar, "FullPath", "REG_DWORD", "1")         ; Enable "Display the full path in the title bar"
RegWrite($regvar, "FullPathAddress", "REG_DWORD", "1")  ; Enable "Display the full path in the address bar"
RegWrite($regvar, "Use Search Asst", "REG_SZ", "no")    ; Disable search assistant

$regvar = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa"
RegWrite($regvar, "ForceGuest", "REG_DWORD", "0")       ; Disable "Use simple file sharing" 

$regvar = "HKCU\Software\Microsoft\Internet Explorer\Main"
RegWrite($regvar, "StatusBarOther", "REG_DWORD", "1")   ; Enable Windows Explorer Status Bar

$regvalue = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel\"
RegWrite($regvalue, "{450D8FBA-AD25-11D0-98A8-0800361B1103}", "REG_DWORD", "0"); Display My Documents icon on Desktop
RegWrite($regvalue, "{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "REG_DWORD", "0"); Display My Computer icon on Desktop
RegWrite($regvalue, "{208D2C60-3AEA-1069-A2D7-08002B30309D}", "REG_DWORD", "0"); Display My Network Places icon on Desktop
RegWrite($regvalue, "{871C5380-42A0-1069-A2EA-08002B30309D}", "REG_DWORD", "0"); Display Internet Explorer icon on Desktop

$regvalue = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu\"
RegWrite($regvalue, "{450D8FBA-AD25-11D0-98A8-0800361B1103}", "REG_DWORD", "0"); Display My Documents icon on Desktop (ClassicStartMenu)
RegWrite($regvalue, "{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "REG_DWORD", "0"); Display My Computer icon on Desktop (ClassicStartMenu)
RegWrite($regvalue, "{208D2C60-3AEA-1069-A2D7-08002B30309D}", "REG_DWORD", "0"); Display My Network Places icon on Desktop (ClassicStartMenu)
RegWrite($regvalue, "{871C5380-42A0-1069-A2EA-08002B30309D}", "REG_DWORD", "0"); Display Internet Explorer icon on Desktop (ClassicStartMenu)

; Set icon view to Details in Explorer for all views
RegDelete("HKEY_CURRENT_USER\Software\Microsoft\Windows\ShellNoRoam\Bags")
RegDelete("HKEY_CURRENT_USER\Software\Microsoft\Windows\ShellNoRoam\BagMRU")
RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Streams", "Settings", "REG_BINARY", "0x08000000040000000000000000777e137335cf11ae6908002b2e1262040000003e00000043000000")
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Streams\Defaults", "{F3364BA0-65B9-11CE-A9BA-00AA004AE837}", "REG_BINARY",
"0x1c0000000400000000000000000090000000000001000000fffffffff0f0f0f01400030090000
0000000000030000000fddfdffd0f0004002000100028003c000000000001
0000000200000003000000b40060007800780000000000010000000200000003000000ffffffff
000000000000000000000000000000000000000000000000000000000000000000000000")

; Apply registry settings NOW! (does not apply Explorer > View Details settings)
RunWait("rundll32 user32.dll,UpdatePerUserSystemParameters")


; Change view setting to Details manually otherwise a logoff/logon is required
Run("explorer"); Open Explorer - Defaults to "My Documents"
WinWaitActive("My Documents"); Wait for window to open
Send("!V")  ; ALT+V selects "View"
Send("D")   ; D selects "Details"

; Open Folder Options from Tools menu
Send("!T")  ; ALT+T selects "Tools"
Sleep(50)
Send("O")   ; O selects "Folder Options"
WinWaitActive("Folder Options"); Wait for "Folder Options" window to open

; Navigate to View tab
Send("+{TAB}"); Shift TAB moves up to General Tab
Sleep(75)
Send("{RIGHT}"); Right arrow moves over to View tab
Sleep(75)
ControlClick("Folder Options", "", "[CLASS:Button; INSTANCE:3]"); Click on the "Reset All Folders" button
WinWaitActive("Folder views"); Wait for yes/no prompt to appear
Send("!Y")  ; Answer Yes to prompt
WinWaitActive("Folder Options"); Wait for "Folder Options" window to open
ControlClick("Folder Options", "", "[CLASS:Button; INSTANCE:2]"); Click "Apply to All Folders"
WinWaitActive("Folder views"); Wait for yes/no prompt to appear
Send("{Y}") ; Y answers Yes to the "Are you sure" prompt
WinWaitActive("Folder Options"); Wait for "Folder Options" window to open
ControlClick("Folder Options", "", "[CLASS:Button; INSTANCE:5]"); Click OK (save and exit window)
WinWaitActive("My Documents")
WinClose("My Documents")

Thanks in advance,

David

Link to comment
Share on other sites

Just sleep until explorer.exe is in the process list then sleep until you can find "[CLASS:Progman; TITLE:Program Manager]"

and if that is not enough then wait for it's "[CLASS:SysListView32; TITLE:FolderView]" (the former using WinGetHandle and the latter using ControlGetHandle), I'm quite sure that it's fully loaded till here. *If applicable ;]

Link to comment
Share on other sites

I checked the help file and couldn't find any simple way of using Sleep with WinGetHandle or ControlGetHandle to detect if Explorer.exe was running. So, I came up with this:

; Loop until Explorer.exe is found in memory
Do
    IsExplorerRunning()             ; Function - Find Explorer and return True or False
    $counter = $counter + 1         ; Loop counter
    Sleep(1000)                 ; Sleep for 1 second
    If $counter = 30 Then ExitScript()  ; If $counter = 30 then give up!
Until $ExplorerFound = True

Func IsExplorerRunning()
    $list = ProcessList("explorer.exe") ; List explorer.exe processes
    For $i = 1 to $list[0][0]
        If $list[$i][0] = "explorer.exe" Then; Is explorer found?
            $ExplorerFound = True   ; Found explorer
        Else
            $ExplorerFound = False  ; No explorer...yet
            Sleep(1000)         ; Sleep for 1 second
        EndIf  
    Next
EndFunc

Func ExitScript()
    MsgBox(0, "Error", "Could not find Explorer.exe after 30 seconds.  Quitting.")
    Exit; Screw it..I give up.
EndFunc

I am sure there is a simpler way of checking to see if explorer is ready but, for now, it works when run from Startup. I haven't tried from a login script yet.

Here is the full script:

$ExplorerFound = False
$counter = 0
Sleep(5000);Sleep for 5 seconds to give Windows a chance to start up


; Set registry settings that would normally be changed using the GUI
$regvar = "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
RegWrite($regvar, "Hidden", "REG_DWORD", "1")           ; Enable "Show hidden files and folders"
RegWrite($regvar, "HideFileExt", "REG_DWORD", "0")      ; Disable "Hide extensions for known file types"
RegWrite($regvar, "ShowSuperHidden", "REG_DWORD", "1")  ; Disable "Hide protected operating system files"
RegWrite($regvar, "TaskbarGlomming", "REG_DWORD", "0")  ; Disable "Group similar taskbar buttons"

$regvar = "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\CabinetState"
RegWrite($regvar, "FullPath", "REG_DWORD", "1")     ; Enable "Display the full path in the title bar"
RegWrite($regvar, "FullPathAddress", "REG_DWORD", "1")  ; Enable "Display the full path in the address bar"
RegWrite($regvar, "Use Search Asst", "REG_SZ", "no")        ; Disable search assistant

$regvar = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa"
RegWrite($regvar, "ForceGuest", "REG_DWORD", "0")       ; Disable "Use simple file sharing" 

$regvar = "HKCU\Software\Microsoft\Internet Explorer\Main"
RegWrite($regvar, "StatusBarOther", "REG_DWORD", "1")   ; Enable Windows Explorer Status Bar

$regvalue = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel\"
RegWrite($regvalue, "{450D8FBA-AD25-11D0-98A8-0800361B1103}", "REG_DWORD", "0"); Display My Documents icon on Desktop
RegWrite($regvalue, "{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "REG_DWORD", "0"); Display My Computer icon on Desktop
RegWrite($regvalue, "{208D2C60-3AEA-1069-A2D7-08002B30309D}", "REG_DWORD", "0"); Display My Network Places icon on Desktop
RegWrite($regvalue, "{871C5380-42A0-1069-A2EA-08002B30309D}", "REG_DWORD", "0"); Display Internet Explorer icon on Desktop

$regvalue = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu\"
RegWrite($regvalue, "{450D8FBA-AD25-11D0-98A8-0800361B1103}", "REG_DWORD", "0"); Display My Documents icon on Desktop (ClassicStartMenu)
RegWrite($regvalue, "{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "REG_DWORD", "0"); Display My Computer icon on Desktop (ClassicStartMenu)
RegWrite($regvalue, "{208D2C60-3AEA-1069-A2D7-08002B30309D}", "REG_DWORD", "0"); Display My Network Places icon on Desktop (ClassicStartMenu)
RegWrite($regvalue, "{871C5380-42A0-1069-A2EA-08002B30309D}", "REG_DWORD", "0"); Display Internet Explorer icon on Desktop (ClassicStartMenu)

; Set icon view to Details in Explorer for all views
RegDelete("HKEY_CURRENT_USER\Software\Microsoft\Windows\ShellNoRoam\Bags")
RegDelete("HKEY_CURRENT_USER\Software\Microsoft\Windows\ShellNoRoam\BagMRU")
RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Streams", "Settings", "REG_BINARY", "0x08000000040000000000000000777e137335cf11ae6908002b2e1262040000003e00000043000000")     ; Set View to Details   
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Streams\Defaults", "{F3364BA0-65B9-11CE-A9BA-00AA004AE837}", "REG_BINARY",
"0x1c0000000400000000000000000090000000000001000000fffffffff0f0f0f014000300900000000000000030
000000fddfdffd0f0004002000100028003c0000000000010000000200000003000000b400600078007800000
00000010000000200000003000000ffffffff00000000000000000000000000000000000000000000000000000
0000000000000000000")

; Code to apply registry settings NOW! (does not apply Explorer View Details settings)
RunWait("rundll32 user32.dll,UpdatePerUserSystemParameters")

; Loop until Explorer.exe is found in memory
Do
    IsExplorerRunning()             ; Function - Find Explorer and return True or False
    $counter = $counter + 1         ; Loop counter
    Sleep(1000)                 ; Sleep for 1 second
    If $counter = 30 Then ExitScript()  ; If $counter = 30 then give up!
Until $ExplorerFound = True

Func IsExplorerRunning()
    $list = ProcessList("explorer.exe") ; List explorer.exe processes
    For $i = 1 to $list[0][0]
        If $list[$i][0] = "explorer.exe" Then; Is explorer found?
            $ExplorerFound = True
        Else
            $ExplorerFound = False
        EndIf  
    Next
EndFunc

Func ExitScript()
    MsgBox(0, "Error", "Could not find Explorer.exe after 30 seconds.  Quitting.")
    Exit
EndFunc

; Change view setting to Details manually otherwise a logoff/logon is required
Run("explorer"); Open Explorer - Defaults to "My Documents"
WinWaitActive("My Documents"); Wait for window to open
Send("!V")  ; ALT+V selects "View"
Send("D")   ; D selects "Details"

; Open Folder Options from Tools menu
Send("!T")  ; ALT+T selects "Tools"
Sleep(50)
Send("O")   ; O selects "Folder Options"
WinWaitActive("Folder Options"); Wait for "Folder Options" window to open

; Navigate to View tab
Send("+{TAB}"); Shift TAB moves up to General Tab
Sleep(75)
Send("{RIGHT}"); Right arrow moves over to View tab
Sleep(75)
ControlClick("Folder Options", "", "[CLASS:Button; INSTANCE:3]"); Click on the "Reset All Folders" button
WinWaitActive("Folder views"); Wait for yes/no prompt to appear
Send("!Y")  ; Answer Yes to prompt
WinWaitActive("Folder Options"); Wait for "Folder Options" window to open
ControlClick("Folder Options", "", "[CLASS:Button; INSTANCE:2]"); Click "Apply to All Folders"
WinWaitActive("Folder views"); Wait for yes/no prompt to appear
Send("{Y}") ; Y answers Yes to the "Are you sure" prompt
WinWaitActive("Folder Options"); Wait for "Folder Options" window to open
ControlClick("Folder Options", "", "[CLASS:Button; INSTANCE:5]"); Click OK (save and exit window)
WinWaitActive("My Documents")
WinClose("My Documents")
Link to comment
Share on other sites

Dim $hProgman
Dim $hFolderView

Do
    Sleep(20)
Until ProcessExists('explorer.exe')
ConsoleWrite('Found explorer.exe' & @LF)

Do
    Sleep(20)
Until WinExists('[TITLE:Program Manager; CLASS:Progman]')
ConsoleWrite('Found Progman' & @LF)

$hProgman = WinGetHandle('[TITLE:Program Manager; CLASS:Progman]')
ConsoleWrite($hProgman & @LF)

Do
    $hFolderView = ControlGetHandle($hProgman, '[TITLE:FolderView; CLASS:SysListView32]', 1)
    Sleep(20)
Until $hFolderView
ConsoleWrite('Found Progman' & @LF & $hFolderView & @LF)

You don't need their handles, just make 2 functions that return True or False if the handle is valid to terminate the loops.

Link to comment
Share on other sites

  • 3 weeks later...

I'm determined to find a way to programatically get Explorere.exe to check for registry changes. I have a programmer friend that is working on that solution and will post it once he gets back to me.

In the mean time I found a different way of waiting for explorer.exe that seems to work very well:

WinWaitActive("My Computer")

This way the script pauses until it sees My Computer then it runs the rest of the script.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...