-
-
Save cmpute/be92e4dfd694696db0ec0c2c5713b45f to your computer and use it in GitHub Desktop.
# This script only works when Google Drive is mounted at G:\ | |
# Change the encoding to UTF-8-BOM before executing this script | |
# To run this file: powershell -noprofile -executionpolicy bypass -file ./PinGoogleDriveFS.ps1 [add/remove] | |
# Settings | |
$ErrorActionPreference = "Stop" | |
$clsid = "{81539FE6-33C7-4CE7-90C7-1C7B8F2F2D41}" # CLSID for personal drive namespace | |
$clsid_i = "{0E5AAE11-A475-4c5b-AB00-C66DE400274E}" # CLSID for personal drive instance | |
$clsid_g = "{FB9411E2-c3F8-4004-BA95-47D459C219D1}" # CLSID for shared drive namespace | |
$clsid_g_i = "{1A223FF4-D08D-4B38-A051-5D2391FE655C}" # CLSID for shared drive instance | |
# 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_clsid_g = "HKCU:\Software\Classes\CLSID\$clsid_g" | |
$hkey_clsid_g64 = "HKCU:\Software\Classes\Wow6432Node\CLSID\$clsid_g" | |
$hkey_ns_g = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\$clsid_g" | |
$hkey_panel = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel" | |
if (($args.Count -eq 0) -or ($args[0].ToLower() -eq "add")) | |
{ | |
trap { "Please run remove first."; break; } | |
# Find the path and folder | |
$gexec = (Get-ItemProperty HKCU:\Software\Classes\GoogleDriveFS.gdoc\DefaultIcon).'(default)' | |
$iconidx = $gexec.Length-2 | |
$drive_icon = $gexec.Remove($iconidx).Insert($iconidx,"16") | |
$drive_icon_g = $gexec.Remove($iconidx).Insert($iconidx,"18") | |
switch ([System.Threading.Thread]::CurrentThread.CurrentCulture.Name) { | |
"en-US" { $folder = "My Drive"; $folder_g = "Shared drives" } | |
"zh-CN" { $folder = "我的云端硬盘" ; $folder_g = "共享云端硬盘" } | |
"nl-BE" { $folder = "Mijn Drive"; $folder_g = "Gedeelde drives" } | |
Default { $folder = "My Drive"; $folder_g = "Shared drives" } | |
} | |
# Update Registry for personal drive | |
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 0x00000040 | |
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 $drive_icon | |
New-Item $hkey_clsid\Instance | |
New-ItemProperty $hkey_clsid\Instance -name "CLSID" -propertyType String -value "$clsid_i" | |
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 0x00000040 | |
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 $drive_icon | |
New-Item $hkey_clsid64\Instance | |
New-ItemProperty $hkey_clsid64\Instance -name "CLSID" -propertyType String -value "$clsid_i" | |
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" | |
# Update Registry for shared drives | |
if(Test-Path "G:\$folder_g") | |
{ | |
New-Item $hkey_clsid_g -itemType String -value "Google Shared Drives" | |
New-ItemProperty $hkey_clsid_g -name "System.IsPinnedToNamespaceTree" -propertyType DWord -value 1 | |
New-ItemProperty $hkey_clsid_g -name "SortOrderIndex" -propertyType DWord -value 0x00000041 | |
New-Item $hkey_clsid_g\InProcServer32 -itemType ExpandString -value "%SYSTEMROOT%\system32\shell32.dll" | |
New-Item $hkey_clsid_g\ShellFolder | |
New-ItemProperty $hkey_clsid_g\ShellFolder -name "FolderValueFlags" -propertyType DWord -value 0x00000028 | |
New-ItemProperty $hkey_clsid_g\ShellFolder -name "Attributes" -propertyType DWord -value 0xf080004d | |
New-Item $hkey_clsid_g\DefaultIcon -itemType String -value $drive_icon_g | |
New-Item $hkey_clsid_g\Instance | |
New-ItemProperty $hkey_clsid_g\Instance -name "CLSID" -propertyType String -value "$clsid_g_i" | |
New-Item $hkey_clsid_g\Instance\InitPropertyBag | |
New-ItemProperty $hkey_clsid_g\Instance\InitPropertyBag -name "Attributes" -propertyType DWord -value 0x00000011 | |
New-ItemProperty $hkey_clsid_g\Instance\InitPropertyBag -name "TargetFolderPath" -propertyType String -value "G:\$folder_g" | |
New-Item $hkey_clsid_g64 -itemType String -value "Google Shared Drives" | |
New-ItemProperty $hkey_clsid_g64 -name "System.IsPinnedToNamespaceTree" -propertyType DWord -value 1 | |
New-ItemProperty $hkey_clsid_g64 -name "SortOrderIndex" -propertyType DWord -value 0x00000041 | |
New-Item $hkey_clsid_g64\InProcServer32 -itemType ExpandString -value "%SYSTEMROOT%\system32\shell32.dll" | |
New-Item $hkey_clsid_g64\ShellFolder | |
New-ItemProperty $hkey_clsid_g64\ShellFolder -name "FolderValueFlags" -propertyType DWord -value 0x00000028 | |
New-ItemProperty $hkey_clsid_g64\ShellFolder -name "Attributes" -propertyType DWord -value 0xf080004d | |
New-Item $hkey_clsid_g64\DefaultIcon -itemType String -value $drive_icon_g | |
New-Item $hkey_clsid_g64\Instance | |
New-ItemProperty $hkey_clsid_g64\Instance -name "CLSID" -propertyType String -value "$clsid_g_i" | |
New-Item $hkey_clsid_g64\Instance\InitPropertyBag | |
New-ItemProperty $hkey_clsid_g64\Instance\InitPropertyBag -name "Attributes" -propertyType DWord -value 0x00000011 | |
New-ItemProperty $hkey_clsid_g64\Instance\InitPropertyBag -name "TargetFolderPath" -propertyType String -value "G:\$folder_g" | |
New-ItemProperty $hkey_panel -name $clsid_g -propertyType DWord -value 1 | |
New-Item $hkey_ns_g -itemType String -value "Google Shared Drives" | |
} | |
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 (Test-Path $hkey_clsid_g) { Remove-Item $hkey_clsid_g -recurse } | |
if (Test-Path $hkey_clsid_g64) { Remove-Item $hkey_clsid_g64 -recurse } | |
if (Test-Path $hkey_ns_g) { Remove-Item $hkey_ns_g -recurse } | |
if ((Get-Item $hkey_panel -EA Ignore).Property -contains $clsid) { Remove-ItemProperty $hkey_panel $clsid } | |
if ((Get-Item $hkey_panel -EA Ignore).Property -contains $clsid_g) { Remove-ItemProperty $hkey_panel $clsid_g } | |
Write-Output "Remove successfully." | |
} | |
else | |
{ | |
Write-Error "The valid option are 'add' and 'remove'" | |
} |
@nijawang Nothing created should be due to the failure to add register entries... But if the script doesn't report any error, then I have no idea about the problem 🤕
@cmpute Thanks!
Here are the log file. Looks like all register entries added, but no Drive FS in sidebar.
Microsoft Windows [Version 10.0.16299.1268]
(c) 2017 Microsoft Corporation. All rights reserved.
C:\>powershell -noprofile -executionpolicy bypass -file ./PinGoogleDriveFS.ps1 remove
Remove successfully.
C:\>powershell -noprofile -executionpolicy bypass -file ./PinGoogleDriveFS.ps1 add
Hive: HKEY_CURRENT_USER\Software\Classes\CLSID
Name Property
---- --------
{81539FE6-33C7-4CE7-90C7-1C7B8 (default) : Google Drive
F2F2D41}
System.IsPinnedToNamespaceTree : 1
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Classes\CLSID\{81539FE6
-33C7-4CE7-90C7-1C7B8F2F2D41}
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Classes\CLSID
PSChildName : {81539FE6-33C7-4CE7-90C7-1C7B8F2F2D41}
PSDrive : HKCU
PSProvider : Microsoft.PowerShell.Core\Registry
SortOrderIndex : 66
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Classes\CLSID\{81539FE6-33C7-4CE7-90C7-
1C7B8F2F2D41}
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Classes\CLSID
PSChildName : {81539FE6-33C7-4CE7-90C7-1C7B8F2F2D41}
PSDrive : HKCU
PSProvider : Microsoft.PowerShell.Core\Registry
Hive: HKEY_CURRENT_USER\Software\Classes\CLSID\{81539FE6-33C7-4CE7-90C7-1C7B8F2F2D41}
Name Property
---- --------
InProcServer32 (default) : C:\WINDOWS\system32\shell32.dll
ShellFolder
FolderValueFlags : 40
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Classes\CLSID\{81539FE6-33C7-4CE7-90C
7-1C7B8F2F2D41}\ShellFolder
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Classes\CLSID\{81539FE6-33C7-4CE7-90C
7-1C7B8F2F2D41}
PSChildName : ShellFolder
PSDrive : HKCU
PSProvider : Microsoft.PowerShell.Core\Registry
Attributes : 4034920525
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Classes\CLSID\{81539FE6-33C7-4CE7-90C7-1C
7B8F2F2D41}\ShellFolder
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Classes\CLSID\{81539FE6-33C7-4CE7-90C7-1C
7B8F2F2D41}
PSChildName : ShellFolder
PSDrive : HKCU
PSProvider : Microsoft.PowerShell.Core\Registry
DefaultIcon (default) : "C:\Program Files\Google\Drive File Stream\32.0.11.0\GoogleDriveFS.exe",0
Instance
CLSID : {0E5AAE11-A475-4c5b-AB00-C66DE400274E}
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Classes\CLSID\{81539FE6-33C7-4CE7-90C7-1C
7B8F2F2D41}\Instance
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Classes\CLSID\{81539FE6-33C7-4CE7-90C7-1C
7B8F2F2D41}
PSChildName : Instance
PSDrive : HKCU
PSProvider : Microsoft.PowerShell.Core\Registry
Hive: HKEY_CURRENT_USER\Software\Classes\CLSID\{81539FE6-33C7-4CE7-90C7-1C7B8F2F2D41}\Instance
Name Property
---- --------
InitPropertyBag
Attributes : 17
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Classes\CLSID\{81539FE6-33C7-4CE7-90C7-1C
7B8F2F2D41}\Instance\InitPropertyBag
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Classes\CLSID\{81539FE6-33C7-4CE7-90C7-1C
7B8F2F2D41}\Instance
PSChildName : InitPropertyBag
PSDrive : HKCU
PSProvider : Microsoft.PowerShell.Core\Registry
TargetFolderPath : G:\My Drive
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Classes\CLSID\{81539FE6-33C7-4CE7-90C
7-1C7B8F2F2D41}\Instance\InitPropertyBag
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Classes\CLSID\{81539FE6-33C7-4CE7-90C
7-1C7B8F2F2D41}\Instance
PSChildName : InitPropertyBag
PSDrive : HKCU
PSProvider : Microsoft.PowerShell.Core\Registry
Hive: HKEY_CURRENT_USER\Software\Classes\Wow6432Node\CLSID
Name Property
---- --------
{81539FE6-33C7-4CE7-90C7-1C7B8 (default) : Google Drive
F2F2D41}
System.IsPinnedToNamespaceTree : 1
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Classes\Wow6432Node\CLS
ID\{81539FE6-33C7-4CE7-90C7-1C7B8F2F2D41}
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Classes\Wow6432Node\CLS
ID
PSChildName : {81539FE6-33C7-4CE7-90C7-1C7B8F2F2D41}
PSDrive : HKCU
PSProvider : Microsoft.PowerShell.Core\Registry
SortOrderIndex : 66
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Classes\Wow6432Node\CLSID\{81539FE6-33C
7-4CE7-90C7-1C7B8F2F2D41}
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Classes\Wow6432Node\CLSID
PSChildName : {81539FE6-33C7-4CE7-90C7-1C7B8F2F2D41}
PSDrive : HKCU
PSProvider : Microsoft.PowerShell.Core\Registry
Hive: HKEY_CURRENT_USER\Software\Classes\Wow6432Node\CLSID\{81539FE6-33C7-4CE7-90C7-1C7B8F2F2D41}
Name Property
---- --------
InProcServer32 (default) : C:\WINDOWS\system32\shell32.dll
ShellFolder
FolderValueFlags : 40
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Classes\Wow6432Node\CLSID\{81539FE6-3
3C7-4CE7-90C7-1C7B8F2F2D41}\ShellFolder
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Classes\Wow6432Node\CLSID\{81539FE6-3
3C7-4CE7-90C7-1C7B8F2F2D41}
PSChildName : ShellFolder
PSDrive : HKCU
PSProvider : Microsoft.PowerShell.Core\Registry
Attributes : 4034920525
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Classes\Wow6432Node\CLSID\{81539FE6-33C7-
4CE7-90C7-1C7B8F2F2D41}\ShellFolder
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Classes\Wow6432Node\CLSID\{81539FE6-33C7-
4CE7-90C7-1C7B8F2F2D41}
PSChildName : ShellFolder
PSDrive : HKCU
PSProvider : Microsoft.PowerShell.Core\Registry
DefaultIcon (default) : "C:\Program Files\Google\Drive File Stream\32.0.11.0\GoogleDriveFS.exe",0
Instance
CLSID : {0E5AAE11-A475-4c5b-AB00-C66DE400274E}
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Classes\Wow6432Node\CLSID\{81539FE6-33C7-
4CE7-90C7-1C7B8F2F2D41}\Instance
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Classes\Wow6432Node\CLSID\{81539FE6-33C7-
4CE7-90C7-1C7B8F2F2D41}
PSChildName : Instance
PSDrive : HKCU
PSProvider : Microsoft.PowerShell.Core\Registry
Hive: HKEY_CURRENT_USER\Software\Classes\Wow6432Node\CLSID\{81539FE6-33C7-4CE7-90C7-1C7B8F2F2D41}\Instance
Name Property
---- --------
InitPropertyBag
Attributes : 17
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Classes\Wow6432Node\CLSID\{81539FE6-33C7-
4CE7-90C7-1C7B8F2F2D41}\Instance\InitPropertyBag
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Classes\Wow6432Node\CLSID\{81539FE6-33C7-
4CE7-90C7-1C7B8F2F2D41}\Instance
PSChildName : InitPropertyBag
PSDrive : HKCU
PSProvider : Microsoft.PowerShell.Core\Registry
TargetFolderPath : G:\My Drive
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Classes\Wow6432Node\CLSID\{81539FE6-3
3C7-4CE7-90C7-1C7B8F2F2D41}\Instance\InitPropertyBag
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Classes\Wow6432Node\CLSID\{81539FE6-3
3C7-4CE7-90C7-1C7B8F2F2D41}\Instance
PSChildName : InitPropertyBag
PSDrive : HKCU
PSProvider : Microsoft.PowerShell.Core\Registry
{81539FE6-33C7-4CE7-90C7-1C7B8F2F2D41} : 1
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windo
ws\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windo
ws\CurrentVersion\Explorer\HideDesktopIcons
PSChildName : NewStartPanel
PSDrive : HKCU
PSProvider : Microsoft.PowerShell.Core\Registry
Hive: HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace
Name Property
---- --------
{81539FE6-33C7-4CE7-90C7-1C7B8 (default) : Google Drive
F2F2D41}
Add successfully
C:\>
@nijawang Rebooting windows did the trick for me.
@cmpute Thanks for adding the team drive functionality! It does add the correct registery keys as I manually verified each one by looking them up in regedit.
The two menu items show up. However unfortunately clicking the sidebar menu for the Team Drive does nothing whereas clicking the sidebar menu for the personal drive correctly opens the appropriate folder. (@svenkle, maybe your experience helps?)
This is really strange as I have been comparing the code you execute for both the personal and team drive and it is exactly the same (apart from the variables of course).
It actually boggles my mind why this does not work properly as all the properties for the different attributes are exactly the same for both personal and team registery keys, as per your script.
Btw, Google decided to rename their folders again:
en-US | zh-CN | nl-BE |
---|---|---|
My Drive | 我的云端硬盘 | Mijn Drive |
Shared drives | 共享云端硬盘 | Gedeelde drives |
The casing for zh-CN might be lower case for 'drives'. This time I could not find the exact translation.
@jotosmurf Did you ever find a solution for the Team Drive ("Shared drives") not working?
@jotosmurf @jonaswouters I can reproduce the problem.. Unfortunately I didn't find any solution. I guess there's difference between the implementation of personal drive and shared drive in the filesystem, which may lead to different "Attributes" flags. But I have no idea which flag need to tweaked.
I updated the script for the new description.
@cmpute I remove original Google Drive sidebar item first as below.
Then I execute "powershell -noprofile -executionpolicy bypass -file ./PinGoogleDriveFS.ps1 add".
But I get nothing added...(I've restarted explorer)
So strange!