Skip to content

Instantly share code, notes, and snippets.

@jbltx
Last active June 28, 2020 07:40
Show Gist options
  • Save jbltx/2465b75e17c228dcd6198c87f68dc325 to your computer and use it in GitHub Desktop.
Save jbltx/2465b75e17c228dcd6198c87f68dc325 to your computer and use it in GitHub Desktop.
[Research] Cloud Storage Client
# Quick notes about Windows registry keys for cloud storage services like MEGA, Dropbox, OneDrive, etc...
# This is UNTESTED so USE IT AT YOUR OWN RISKS
# CONSTANTS
$UUID_FOLDER = "{$([guid]::NewGuid().Guid)}" # Used to add a 'cloud storage'-like folder in Explorer Pane
$UUID_CONTEXTMENU = "{$([guid]::NewGuid().Guid)}" # Used to add a context-menu, property sheets, etc... on files and folders
$UUID_OVERLAY1 = "{$([guid]::NewGuid().Guid)}" # Used for icon overlay on files' icon
$UUID_OVERLAY2 = "{$([guid]::NewGuid().Guid)}"
$UUID_OVERLAY3 = "{$([guid]::NewGuid().Guid)}"
$UUID_OVERLAY4 = "{$([guid]::NewGuid().Guid)}"
$APP_NAME = "My App"
$APP_NAME_CAMELCASE = "MyApp"
$FOLDER_NAME = "My App Folder"
$APP_BINARY_FILE_PATH = "$((Get-Item -Path Env:ALLUSERSPROFILE).Value)\${APP_NAME}\${APP_NAME}.exe"
$TARGET_FOLDER_PATH = "F:\MyCloudStorageFolder"
$CUSTOM_SHELL_EXT_LIB = "$((Get-Item -Path Env:ALLUSERSPROFILE).Value)\${APP_NAME}\ShellExtX64.dll"
# https://docs.microsoft.com/en-us/windows/desktop/shell/reg-shell-exts
# We use HKEY_CLASSES_ROOT here, since Windows will automatically copy these values in HKEY_LOCAL_MACHINE\Software\Classes
New-PSDrive -PSProvider registry -Root HKEY_CLASSES_ROOT -Name HKCR
# 1 - Register Shell Extension Handlers for all UUIDs
New-Item –Path "HKCR:\CLSID" –Name "${UUID_CONTEXTMENU}" -Value "${APP_NAME_CAMELCASE}"
New-Item –Path "HKCR:\CLSID\${UUID_CONTEXTMENU}" –Name "InprocServer32" -Value "${CUSTOM_SHELL_EXT_LIB}"
New-ItemProperty -Path "HKCR:\CLSID\${UUID_CONTEXTMENU}\InprocServer32" -Name "ThreadingModel" -Value "Apartment" -PropertyType "String"
New-Item –Path "HKCR:\CLSID" –Name "${UUID_OVERLAY1}" -Value "${APP_NAME_CAMELCASE}"
New-Item –Path "HKCR:\CLSID\${UUID_OVERLAY1}" –Name "InprocServer32" -Value "${CUSTOM_SHELL_EXT_LIB}"
New-ItemProperty -Path "HKCR:\CLSID\${UUID_OVERLAY1}\InprocServer32" -Name "ThreadingModel" -Value "Apartment" -PropertyType "String"
New-Item –Path "HKCR:\CLSID" –Name "${UUID_OVERLAY2}" -Value "${APP_NAME_CAMELCASE}"
New-Item –Path "HKCR:\CLSID\${UUID_OVERLAY2}" –Name "InprocServer32" -Value "${CUSTOM_SHELL_EXT_LIB}"
New-ItemProperty -Path "HKCR:\CLSID\${UUID_OVERLAY2}\InprocServer32" -Name "ThreadingModel" -Value "Apartment" -PropertyType "String"
New-Item –Path "HKCR:\CLSID" –Name "${UUID_OVERLAY3}" -Value "${APP_NAME_CAMELCASE}"
New-Item –Path "HKCR:\CLSID\${UUID_OVERLAY3}" –Name "InprocServer32" -Value "${CUSTOM_SHELL_EXT_LIB}"
New-ItemProperty -Path "HKCR:\CLSID\${UUID_OVERLAY3}\InprocServer32" -Name "ThreadingModel" -Value "Apartment" -PropertyType "String"
New-Item –Path "HKCR:\CLSID" –Name "${UUID_OVERLAY4}" -Value "${APP_NAME_CAMELCASE}"
New-Item –Path "HKCR:\CLSID\${UUID_OVERLAY4}" –Name "InprocServer32" -Value "${CUSTOM_SHELL_EXT_LIB}"
New-ItemProperty -Path "HKCR:\CLSID\${UUID_OVERLAY4}\InprocServer32" -Name "ThreadingModel" -Value "Apartment" -PropertyType "String"
# 1.5 - Register Shell Extension Handlers (32bits)
# Same as 1, but in HKEY_CLASSES_ROOT\WOW6432Node\CLSID\...
# 2 - Add those UUIDs in Shell white-list
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved" -Name "${UUID_CONTEXTMENU}" -PropertyType "String" -Value "${APP_NAME_CAMELCASE}"
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved" -Name "${UUID_OVERLAY1}" -PropertyType "String" -Value " ${APP_NAME_CAMELCASE}UpToDate"
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved" -Name "${UUID_OVERLAY2}" -PropertyType "String" -Value " ${APP_NAME_CAMELCASE}UpdatePending"
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved" -Name "${UUID_OVERLAY3}" -PropertyType "String" -Value " ${APP_NAME_CAMELCASE}Updating"
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved" -Name "${UUID_OVERLAY4}" -PropertyType "String" -Value " ${APP_NAME_CAMELCASE}NotFound"
# 3 - Register for context menu
New-Item –Path "HKCR:\*\shellex\ContextMenuHandlers" -Name "${APP_NAME_CAMELCASE}" -Value "${UUID_CONTEXTMENU}"
New-Item –Path "HKCR:\AllFilesystemObjects\shellex\ContextMenuHandlers" -Name "${APP_NAME_CAMELCASE}" -Value "${UUID_CONTEXTMENU}"
New-Item –Path "HKCR:\Directory\shellex\ContextMenuHandlers" -Name "${APP_NAME_CAMELCASE}" -Value "${UUID_CONTEXTMENU}"
New-Item –Path "HKCR:\Drive\shellex\ContextMenuHandlers" -Name "${APP_NAME_CAMELCASE}" -Value "${UUID_CONTEXTMENU}"
# 4 - Register for property sheet
New-Item –Path "HKCR:\*\shellex\PropertySheetHandlers" -Name "${APP_NAME_CAMELCASE}" -Value "${UUID_CONTEXTMENU}"
New-Item –Path "HKCR:\AllFilesystemObjects\shellex\PropertySheetHandlers" -Name "${APP_NAME_CAMELCASE}" -Value "${UUID_CONTEXTMENU}"
New-Item –Path "HKCR:\Directory\shellex\PropertySheetHandlers" -Name "${APP_NAME_CAMELCASE}" -Value "${UUID_CONTEXTMENU}"
New-Item –Path "HKCR:\Drive\shellex\PropertySheetHandlers" -Name "${APP_NAME_CAMELCASE}" -Value "${UUID_CONTEXTMENU}"
# 5 - Register Folder Details View custom column
# REG ADD "HKEY_CLASSES_ROOT\Folder\shellex\ColumnHandlers\${APP_NAME_CAMELCASE}" /VE /T REG_SZ /D "${UUID_CONTEXTMENU}" /F
# Icon Overlay Handlers = Check file status between client and server using a small icon over the file icon
# https://docs.microsoft.com/en-us/windows/desktop/shell/how-to-register-icon-overlay-handlers
# 6 - Register ShellIconOverlayIdentifiers
New-Item –Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers" -Name " ${APP_NAME_CAMELCASE}UpToDate" -Value "${UUID_OVERLAY1}"
New-Item –Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers" -Name " ${APP_NAME_CAMELCASE}UpdatePending" -Value "${UUID_OVERLAY2}"
New-Item –Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers" -Name " ${APP_NAME_CAMELCASE}Updating" -Value "${UUID_OVERLAY3}"
New-Item –Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers" -Name " ${APP_NAME_CAMELCASE}NotFound" -Value "${UUID_OVERLAY4}"
# A special virtual folder in the explorer pane = Direct access to storage
# https://docs.microsoft.com/en-us/windows/desktop/shell/integrate-cloud-storage
# This part is made under HKEY_CURRENT_USER because we set the folder in Explorer panel just for the current user
# Register your application folder
New-Item –Path "HKCU:\SOFTWARE\Classes\CLSID\" -Name "${UUID_FOLDER}" -Value "${FOLDER_NAME}"
# Set the location for your extension in the Navigation Pane (0x0 = first one in the list)
New-ItemProperty -Path "HKCU:\SOFTWARE\Classes\CLSID\${UUID_FOLDER}" -Name "SortOrderIndex" -Value 0x0 -PropertyType "DWord"
# Add your extension to the Navigation Pane and make it visible
New-ItemProperty -Path "HKCU:\SOFTWARE\Classes\CLSID\${UUID_FOLDER}" -Name "System.IsPinnedToNamespaceTree" -Value 0x1 -PropertyType "DWord"
# Add a custom icon (use the binary file path to have the same icon as the app)
New-Item –Path "HKCU:\SOFTWARE\Classes\CLSID\${UUID_FOLDER}" -Name "DefaultIcon" -Value "${APP_BINARY_FILE_PATH}"
# Use the shell32.dll to emulate default windows folders
New-Item –Path "HKCU:\SOFTWARE\Classes\CLSID\${UUID_FOLDER}" -Name "InProcServer32" -Value "%SYSTEMROOT%\System32\shell32.dll"
# Indicate that your namespace extension should function like other file folder structures in File Explorer
New-Item –Path "HKCU:\SOFTWARE\Classes\CLSID\${UUID_FOLDER}" -Name "Instance"
New-ItemProperty –Path "HKCU:\SOFTWARE\Classes\CLSID\${UUID_FOLDER}\Instance" -Name "CLSID" -Value "{0E5AAE11-A475-4c5b-AB00-C66DE400274E}" -PropertyType "String"
# Set the directory attributes: FILE_ATTRIBUTE_DIRECTORY = 0x10 (To add it read-only, use FILE_ATTRIBUTE_READONLY=0x1 (total = 0x11))
New-Item –Path "HKCU:\SOFTWARE\Classes\CLSID\${UUID_FOLDER}\Instance" -Name "InitPropertyBag"
New-ItemProperty –Path "HKCU:\SOFTWARE\Classes\CLSID\${UUID_FOLDER}\Instance\InitPropertyBag" -Name "Attributes" -Value 0x10 -PropertyType "DWord"
# Set the target folder path
New-ItemProperty –Path "HKCU:\SOFTWARE\Classes\CLSID\${UUID_FOLDER}\Instance\InitPropertyBag" -Name "TargetFolderPath" -Value "${TARGET_FOLDER_PATH}" -PropertyType "ExpandString"
# Set some flags necessary to pin your namespace extension to the File Explorer tree
New-Item –Path "HKCU:\SOFTWARE\Classes\CLSID\${UUID_FOLDER}" -Name "ShellFolder"
New-ItemProperty –Path "HKCU:\Software\Classes\CLSID\${UUID_FOLDER}\ShellFolder" -Name "FolderValueFlags" -Value 0x28 -PropertyType "DWord"
# Set the appropriate flags to control your shell behavior
New-ItemProperty –Path "HKCU:\Software\Classes\CLSID\${UUID_FOLDER}\ShellFolder" -Name "Attributes" -Value 0xF080004D -PropertyType "DWord"
# Configure the namespace extension to be a child of the desktop folder
New-Item –Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\Namespace" -Name "${UUID_FOLDER}" -Value "${APP_NAME_CAMELCASE}"
# Hide your extension from the Desktop
New-ItemProperty –Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\HideDesktopIcons\NewStartPanel" -Name "${UUID_FOLDER}" -Value 0x1 -PropertyType "DWord"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment