Instantly share code, notes, and snippets.

Embed
What would you like to do?
Pin Google Drive File Stream to Explorer Sidebar
# Settings
$clsid = "{81539FE6-33C7-4CE7-90C7-1C7B8F2F2D41}" # CLSID for this shortcut
# Affected keys
$hkey_clsid = "HKCU:\Software\Classes\CLSID\$clsid"
$hkey_clsid64 = "HKCU:\Software\Classes\Wow6432Node\CLSID\$clsid"
$hkey_ns = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\$clsid"
$hkey_panel = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel"
if (($args.Count -eq 0) -or ($args[0].ToLower() -eq "add"))
{
# Find the path and folder
$gexec = (Get-ItemProperty HKCU:\Software\Classes\GoogleDriveFS.gdoc\DefaultIcon).'(default)'
$iconidx = $gexec.Length-2
$gexec = $gexec.Remove($iconidx).Insert($iconidx,"0")
switch ([System.Threading.Thread]::CurrentThread.CurrentCulture.Name) {
"en-US" { $folder = "My Drive" }
"zh-CN" { $folder = "我的云端硬盘" }
Default { $folder = "My Drive" }
}
# Update Registry
New-Item $hkey_clsid -itemType String -value "Google Drive"
New-ItemProperty $hkey_clsid -name "System.IsPinnedToNamespaceTree" -propertyType DWord -value 1
New-ItemProperty $hkey_clsid -name "SortOrderIndex" -propertyType DWord -value 0x00000042
New-Item $hkey_clsid\InProcServer32 -itemType ExpandString -value "%SYSTEMROOT%\system32\shell32.dll"
New-Item $hkey_clsid\ShellFolder
New-ItemProperty $hkey_clsid\ShellFolder -name "FolderValueFlags" -propertyType DWord -value 0x00000028
New-ItemProperty $hkey_clsid\ShellFolder -name "Attributes" -propertyType DWord -value 0xf080004d
New-Item $hkey_clsid\DefaultIcon -itemType String -value $gexec
New-Item $hkey_clsid\Instance
New-ItemProperty $hkey_clsid\Instance -name "CLSID" -propertyType String -value "{0E5AAE11-A475-4c5b-AB00-C66DE400274E}"
New-Item $hkey_clsid\Instance\InitPropertyBag
New-ItemProperty $hkey_clsid\Instance\InitPropertyBag -name "Attributes" -propertyType DWord -value 0x00000011
New-ItemProperty $hkey_clsid\Instance\InitPropertyBag -name "TargetFolderPath" -propertyType String -value "G:\$folder"
New-Item $hkey_clsid64 -itemType String -value "Google Drive"
New-ItemProperty $hkey_clsid64 -name "System.IsPinnedToNamespaceTree" -propertyType DWord -value 1
New-ItemProperty $hkey_clsid64 -name "SortOrderIndex" -propertyType DWord -value 0x00000042
New-Item $hkey_clsid64\InProcServer32 -itemType ExpandString -value "%SYSTEMROOT%\system32\shell32.dll"
New-Item $hkey_clsid64\ShellFolder
New-ItemProperty $hkey_clsid64\ShellFolder -name "FolderValueFlags" -propertyType DWord -value 0x00000028
New-ItemProperty $hkey_clsid64\ShellFolder -name "Attributes" -propertyType DWord -value 0xf080004d
New-Item $hkey_clsid64\DefaultIcon -itemType String -value $gexec
New-Item $hkey_clsid64\Instance
New-ItemProperty $hkey_clsid64\Instance -name "CLSID" -propertyType String -value "{0E5AAE11-A475-4c5b-AB00-C66DE400274E}"
New-Item $hkey_clsid64\Instance\InitPropertyBag
New-ItemProperty $hkey_clsid64\Instance\InitPropertyBag -name "Attributes" -propertyType DWord -value 0x00000011
New-ItemProperty $hkey_clsid64\Instance\InitPropertyBag -name "TargetFolderPath" -propertyType String -value "G:\$folder"
New-ItemProperty $hkey_panel -name $clsid -propertyType DWord -value 1
New-Item $hkey_ns -itemType String -value "Google Drive"
Write-Output "Add successfully"
}
elseif ($args[0].ToLower() -eq "remove")
{
if (Test-Path $hkey_clsid) { Remove-Item $hkey_clsid -recurse }
if (Test-Path $hkey_clsid64) { Remove-Item $hkey_clsid64 -recurse }
if (Test-Path $hkey_ns) { Remove-Item $hkey_ns -recurse }
if ((Get-Item $hkey_panel -EA Ignore).Property -contains $clsid) {
Remove-ItemProperty $hkey_panel $clsid
}
Write-Output "Remove successfully."
}
else
{
Write-Error "The valid option are 'add' and 'remove'"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment