The following is a method to generate a Places Bar configuration on an application specific basis. The method was got from Cutting Edge.
The code below is quick and dirty and simply demonstrates the method.
It relies on the registry function RegOverridePredefKey which was introduced in Win2000 so will not not work on an NT kernel prior and, of course, the 9x/Me platform. The code does not check the OS version.
The principle is to map a pre-defined key to another key.
In the following post I have listed the Dword values available for the system folders.
On executing, an open file dialog is displayed. Do not Cancel yet. Run Notepad, for example, and display an open file dialog. This second open file dialog will use the global Places Bar.
The method employed may, of course, be used on other aspects which have a global nature.
That is it. Have fun.
The code below is quick and dirty and simply demonstrates the method.
It relies on the registry function RegOverridePredefKey which was introduced in Win2000 so will not not work on an NT kernel prior and, of course, the 9x/Me platform. The code does not check the OS version.
The principle is to map a pre-defined key to another key.
In the following post I have listed the Dword values available for the system folders.
On executing, an open file dialog is displayed. Do not Cancel yet. Run Notepad, for example, and display an open file dialog. This second open file dialog will use the global Places Bar.
The method employed may, of course, be used on other aspects which have a global nature.
That is it. Have fun.

Code:
#Compile Exe '8.04
#REGISTER NONE
#DIM ALL
#TOOLS OFF
#Include "WIN32API.inc" ' 20 April 2007
#Include "COMDLG32.inc" ' 1 November 2006
' The following three functions are by Pierre Bellisle
Declare Function RegKeySet(Dword, String) As Long
Declare Function RegDataSet(Dword, String, String, String, ByVal Dword) As Long
Declare Function RegKeyDelTreeRecursive(Dword, String) As Long
Function PBMain( ) As Long
Local zMyHKCU As Asciiz * 256
Local hMyHKCU As Dword ' MyHKCU handle
' Create the key that we are going to map to
zMyHKCU = "MyHKCU"
If RegCreateKeyEx( %HKEY_CURRENT_USER, zMyHKCU, ByVal %Null, ByVal %Null, %REG_OPTION_NON_VOLATILE, %KEY_ALL_ACCESS, ByVal %Null, hMyHKCU, ByVal %Null ) <> %Error_Success Then
MsgBox "Failed to create MyHKCU"
Exit Function
End If
' Create redirection - we are going to map HKEY_CURRENT_USER to MyHKCU
' MyHKCU must remain open
If RegOverridePredefKey( %HKEY_CURRENT_USER, hMyHKCU ) <> %Error_Success Then
MsgBox "Failed to create mapping key"
Exit Function
End If
' Note: MyHKCU is empty at this stage.
' Any writes to HKEY_CURRENT_USER from now on will be mapped To MyHKCU - HKEY_CURRENT_USER will remain intact
' Any reads from HKEY_CURRENT_USER other than mapped entries will fail - they do not exist in mapped domain
'It is now safe to close MyHKCU
RegCloseKey hMyHKCU
' Do not hide extensions for known file types
If RegDataSet(%HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced","HideFileExt","&h00", %REG_DWORD) <> %Error_Success Then
MsgBox "Failed to write data"
Exit Function
End If
' Populate the PlacesBar key
' Example using Dword
If RegDataSet(%HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Policies\comdlg32\PlacesBar", "Place0", "&h11", %REG_DWORD) <> %Error_Success Then
MsgBox "Failed to write data"
Exit Function
End If
'Example using path
If RegDataSet(%HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Policies\comdlg32\PlacesBar", "Place1", "C:\", %REG_SZ) <> %Error_Success Then
MsgBox "Failed to write data"
Exit Function
End If
'Example using environment variable
If RegDataSet(%HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Policies\comdlg32\PlacesBar", "Place2", "%ProgramFiles%", %REG_EXPAND_SZ) <> %Error_Success Then
MsgBox "Failed to write data"
Exit Function
End If
' Now cancel redirection - HKEY_CURRENT_USER is now available as normal
RegOverridePredefKey( %HKEY_CURRENT_USER, ByVal %Null )
' OK, now lets use our application specific Places Bar
' -----------------------------------------------------------------------------------------------------
' Open MyHKCU for mapping
If RegOpenKeyEx( %HKEY_CURRENT_USER, zMyHKCU, ByVal %Null, %KEY_READ, hMyHKCU ) <> %Error_Success Then
MsgBox "Failed to open MyHKCU"
End If
' Create redirection
If RegOverridePredefKey( %HKEY_CURRENT_USER, hMyHKCU ) <> %Error_Success Then
MsgBox "Failed to create mapping key"
Exit Function
End If
RegCloseKey hMyHKCU
' Now test
OPENFILEDIALOG( 0, "Select a file", "", "", "All Files (*.*)|*.*", "*", %OFN_FILEMUSTEXIST Or %OFN_FORCESHOWHIDDEN Or %OFN_HIDEREADONLY )
' Cancel redirection
RegOverridePredefKey( %HKEY_CURRENT_USER, ByVal %Null )
' -----------------------------------------------------------------------------------------------------
' and finally delete the mapped key
If RegKeyDelTreeRecursive( %HKEY_CURRENT_USER, "MyHKCU" ) <> %Error_Success Then MsgBox "MyHKCU deletion failed"
' -----------------------------------------------------------------------------------------------------
End Function
' **********
Function RegKeySet(hMainKey As Dword, sKeyName As String) As Long
'Create one or many level of key. Return %ERROR_SUCCESS (0) if no error.
'Retval = RegKeySet(%HKEY_LOCAL_MACHINE, "SOFTWARE\A_registry_test")
Local hKey As Dword
Local dwDisp As Dword
Function = RegCreateKeyEx(hMainKey, ByVal StrPtr(SKeyName), ByVal %Null, "", %REG_OPTION_NON_VOLATILE, _
%KEY_ALL_ACCESS, ByVal %Null, hKey, dwDisp)
If hKey Then RegCloseKey(hKey)
End Function
Function RegDataSet(hMainKey As Dword, sKeyName As String, sValueName As String, _
sData As String, ByVal dwDataType As Dword) As Long
'Create value if necessary and set data. Return %ERROR_SUCCESS (0) if no error.
'RegDataSet(%HKEY_LOCAL_MACHINE, "SOFTWARE\A_registry_test", "", "DefaultData", %REG_SZ)
'RegDataSet(%HKEY_LOCAL_MACHINE, "SOFTWARE\A_registry_test", "Value REG_SZ", "SomeData", %REG_SZ)
'RegDataSet(%HKEY_LOCAL_MACHINE, "SOFTWARE\A_registry_test", "Value REG_MULTI_SZ", "SomeData" & $NUL & "MoreData" & $NUL & "NoMoreData", %REG_MULTI_SZ)
'RegDataSet(%HKEY_LOCAL_MACHINE, "SOFTWARE\A_registry_test", "Value REG_EXPAND_SZ", "%ProgramFiles%\SomeFolder", %REG_EXPAND_SZ)
'RegDataSet(%HKEY_LOCAL_MACHINE, "SOFTWARE\A_registry_test", "Value REG_DWORD", "1234567890", %REG_DWORD)
Local hKey As Dword
Local DalaLen As Dword
Local dwData As Dword
Local Retval As Long
Local pData As Dword
Retval = RegOpenKeyEx(hMainKey, ByVal StrPtr(sKeyName), ByVal %Null, %KEY_ALL_ACCESS, hKey)
If Retval = %ERROR_FILE_NOT_FOUND Then
RegKeySet(hMainKey, sKeyName)
Retval = RegOpenKeyEx(hMainKey, ByVal StrPtr(sKeyName), ByVal %Null, %KEY_ALL_ACCESS, hKey)
End If
If Retval = %ERROR_SUCCESS Then
If dwDataType = %REG_DWORD Then
dwData = Val(sData)
pData = VarPtr(dwData)
DalaLen = 4
Else
pData = StrPtr(sData)
DalaLen = Len(sData) 'Use LEN not SIZEOFF
End If
Retval = RegSetValueEx(hKey, ByVal StrPtr(sValueName), ByVal %Null, dwDataType, ByVal pData, ByVal DalaLen)
RegCloseKey(hKey)
End If
Function = Retval
End Function
Function RegKeyDelTreeRecursive(hMainKey As Dword, sKeyToDel As String) As Long
'Delete a key and and everything under recursively. Return %ERROR_SUCCESS (0) if no error.
'RegKeyDelTreeRecursive(%HKEY_LOCAL_MACHINE, "SOFTWARE\A_registry_test\KeyToDel")
Local zBuffer As Asciiz * 16384
Local zBufferLen As Dword
Local hKey As Dword
Static dwDeep As Dword
Static ErrorCount As Long
Local RetVal As Long
If dwDeep = 0 Then ErrorCount = 0 'Reset ErrorCount
Incr dwDeep 'Keep track of auto recursion deepness
If RegOpenKeyEx(hMainKey, ByVal StrPtr(sKeyToDel), 0, %KEY_ALL_ACCESS, hKey) = %ERROR_SUCCESS Then
Do 'Enumerate all values and delete each one
zBufferLen = SizeOf(zBuffer)
Retval = RegEnumValue(hKey, ByVal 0, zBuffer, zBufferLen, ByVal %Null, ByVal %Null, ByVal %Null, ByVal %Null)
If Retval <> %ERROR_SUCCESS Then
If Retval <> %ERROR_NO_MORE_ITEMS Then Incr ErrorCount ': MsgBox "%ERROR_NO_MORE_ITEMS"
Exit Do 'No value found, so exit
End If
Retval = RegDeleteValue(hKey, ByVal VarPtr(zBuffer)) 'Delete the value
If Retval Then Incr ErrorCount
Loop
Do 'Enumerate all key and delete each one
zBufferLen = SizeOf(zBuffer)
Retval = RegEnumKeyEx(hKey, ByVal 0, zBuffer, zBufferLen, 0, ByVal %Null, ByVal %Null, ByVal %Null)
If Retval <> %ERROR_SUCCESS Then
If Retval <> %ERROR_NO_MORE_ITEMS Then Incr ErrorCount ': MsgBox "%ERROR_NO_MORE_ITEMS"
Exit Do 'No key found, so exit
End If
RegKeyDelTreeRecursive hMainKey, sKeyToDel & "\" & zBuffer 'The function call itself to go deeper doing a recursive action
zBuffer = sKeyToDel & "\" & zBuffer
Retval = RegDeleteKey(hMainKey, ByVal VarPtr(zBuffer)) 'Delete founded keys
If Retval Then Incr ErrorCount
Loop
RegCloseKey hKey
Else
Incr ErrorCount
End If
Decr dwDeep 'Recursion is all done when dwDeep is back to zero
If dwDeep = 0 Then
'Job is almost done, still have to delete the sKeyToDel
'that was set before any recursion occured
Retval = RegDeleteKey(hMainKey, ByVal StrPtr(sKeyToDel))
If Retval Then Incr ErrorCount
End If
Function = ErrorCount ': MsgBox Str$(ErrorCount)
End Function
' **********
Comment