none
"Single-click to open" in Windows Explorer registry

    Question

  • Hello to all,

    I would like to set as a default  option "Single-click to open an item" in Windows Explorer. User can do it  manually via "Folder and Search Options"-> "General" tab. However I need to do it upon application install using VBScript/WMI -  this is customer's request  . This setting is stored somewhere in registry but I cant find which keys shall I update -  I suppose there are several key values to change. Where can I find this keys description?

    Do Win XP and Vista use same keys for this option?

    Thanks in advance,

    David

     

    Sunday, July 03, 2011 7:40 AM

Answers

  • Hi, David:

    Explorer settings are persisted in what is called the "shell state". There's a structure with bit fields in the Windows API, SHELLSTATE, that stores the information you're looking for. The field you are interested in is "fDoubleClickInWebView" (see the documentation in the MSDN article I linked before).

    The SHELLSTATE structure is stored in the registry, specifically in the "ShellState" value of this registry key: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\

    Here's some source code, in VBS:

     

    '
    ' Small example of VBScript code that switches between "double click to open items" and "single click to open
    ' items" by editing the ShellState binary value in the registry.
    ' It depends on the layout of the SHELLSTATE structure, so it might cease to work in future versions of
    ' Windows.
    '
    ' For unmanaged code, the best way to achieve this is using the SHGetSetSettings function with the
    ' second parameter set to SSF_DOUBLECLICKINWEBVIEW 
    '
    ' (c) Daniel Martín
    '
    Const HKEY_CURRENT_USER = &H80000001
    strComputer = "."
    Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
    Set objWMIService = GetObject("winmgmts:"& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set objShell = CreateObject("Wscript.Shell") 
    
    strPath = "Software\Microsoft\Windows\CurrentVersion\Explorer"
    strBinValue = "ShellState"
    
    objRegistry.GetBinaryValue HKEY_CURRENT_USER, strPath, strBinValue, uBinaryShellState
    uBinaryNewShellState = uBinaryShellState ' Keep user settings
    uBinaryNewShellState(4) = uBinaryShellState(4) Xor 32 ' But toggle the fDoubleClickInWebView bit
    objRegistry.SetBinaryValue HKEY_CURRENT_USER, strPath, strBinValue, uBinaryNewShellState
    
    If (Return = 0) And (Err.Number = 0) Then
    	If ((uBinaryShellState(4) Or 32) = uBinaryShellState(4)) Then
    		MsgBox "Single click to open items was applied successfully. Restarting Explorer..."
    	Else
    		MsgBox "Double click to open items was applied successfully. Restarting Explorer..."
    	End If
    	Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'explorer.exe'")
    	For Each objProcess in colProcessList
    		objProcess.Terminate(1)
    	Next
    	objShell.Run "explorer.exe"
    Else
    	MsgBox "An error occurred: " + Err.Number
    End If
    

     


    Microsoft MVP Windows Expert Consumer | http://www.wintecnico.com


    • Marked as answer by David_bubu Monday, July 04, 2011 12:21 PM
    Sunday, July 03, 2011 3:56 PM
    Answerer

All replies

  • Hi David_bubu,

    You have to set the following registry key:

    Windows Registry Editor Version 5.00

    [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer]
    "ShellState"=hex:24,00,00,00,18,28,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
      01,00,00,00,12,00,00,00,00,00,00,00,22,00,00,00
    "IconUnderline"=dword:00000002

    Just Copy and Paste into a Notepad and save it with .REG type of file.

    *Note that "ShellState" is for "Single-Click to open an item" and "IconUnderline" with value "2" is for  "Underline icon titles consistent with my browser", "IconUnderline" with value "3" is for "Underline icon titles only when I point at them"

    After you apply the registry key, you have to Log off or Restart your system in orden you can see the change.

    As you said, Windows Vista and Windows XP normally (Not always in XP) use the same keys.

    Please, be careful.

     




    Sunday, July 03, 2011 3:07 PM
  • Hi, David:

    Explorer settings are persisted in what is called the "shell state". There's a structure with bit fields in the Windows API, SHELLSTATE, that stores the information you're looking for. The field you are interested in is "fDoubleClickInWebView" (see the documentation in the MSDN article I linked before).

    The SHELLSTATE structure is stored in the registry, specifically in the "ShellState" value of this registry key: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\

    Here's some source code, in VBS:

     

    '
    ' Small example of VBScript code that switches between "double click to open items" and "single click to open
    ' items" by editing the ShellState binary value in the registry.
    ' It depends on the layout of the SHELLSTATE structure, so it might cease to work in future versions of
    ' Windows.
    '
    ' For unmanaged code, the best way to achieve this is using the SHGetSetSettings function with the
    ' second parameter set to SSF_DOUBLECLICKINWEBVIEW 
    '
    ' (c) Daniel Martín
    '
    Const HKEY_CURRENT_USER = &H80000001
    strComputer = "."
    Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
    Set objWMIService = GetObject("winmgmts:"& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set objShell = CreateObject("Wscript.Shell") 
    
    strPath = "Software\Microsoft\Windows\CurrentVersion\Explorer"
    strBinValue = "ShellState"
    
    objRegistry.GetBinaryValue HKEY_CURRENT_USER, strPath, strBinValue, uBinaryShellState
    uBinaryNewShellState = uBinaryShellState ' Keep user settings
    uBinaryNewShellState(4) = uBinaryShellState(4) Xor 32 ' But toggle the fDoubleClickInWebView bit
    objRegistry.SetBinaryValue HKEY_CURRENT_USER, strPath, strBinValue, uBinaryNewShellState
    
    If (Return = 0) And (Err.Number = 0) Then
    	If ((uBinaryShellState(4) Or 32) = uBinaryShellState(4)) Then
    		MsgBox "Single click to open items was applied successfully. Restarting Explorer..."
    	Else
    		MsgBox "Double click to open items was applied successfully. Restarting Explorer..."
    	End If
    	Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'explorer.exe'")
    	For Each objProcess in colProcessList
    		objProcess.Terminate(1)
    	Next
    	objShell.Run "explorer.exe"
    Else
    	MsgBox "An error occurred: " + Err.Number
    End If
    

     


    Microsoft MVP Windows Expert Consumer | http://www.wintecnico.com


    • Marked as answer by David_bubu Monday, July 04, 2011 12:21 PM
    Sunday, July 03, 2011 3:56 PM
    Answerer
  • Thanks, that was very helpful !
    Monday, July 04, 2011 12:21 PM
  • Thanks, that was very helpful !
    Monday, July 04, 2011 12:21 PM
  • Thanks for your input!
    Monday, July 04, 2011 12:22 PM