forked from gangstanthony/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Create-ThisPcPin.ps1
132 lines (124 loc) · 12.2 KB
/
Create-ThisPcPin.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# https://winaero.com/blog/add-custom-folders-or-control-panel-applets-to-navigation-pane-in-file-explorer/
<#
.example
Create-ThisPcPin -name "google drive" -path "c:\users\name\google drive"
.example
Create-ThisPcPin -name "google drive" -delete # -force
#>
function Create-ThisPcPin {
param (
$name,
$path,
[switch]$delete,
[switch]$force
)
$sid = ([System.Security.Principal.WindowsIdentity]::GetCurrent()).User.Value
if ($delete) {
New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS
$item = dir "hku:\$sid\Software\Classes\CLSID\" | ? {(Get-ItemProperty $_.pspath).'(default)' -ceq $name}
$guid = (Split-Path $item.name -Leaf).trim('{}')
if (!$guid) {
throw "Could not find: $name"
} else {
if (!$force) {
$createdby = (Get-ItemProperty $item.PSPath).CreatedBy
if ($createdby -ne 'Create-ThisPcPin') {
$answer = Read-Host 'Looks like this Pin was not created by Create-ThisPcPin. Delete anyway? y/[N]'
if ($answer -ne 'y') {
return
}
}
}
}
Remove-PSDrive hku
reg delete "HKU\$sid\Software\Classes\CLSID\{$GUID}" /f
reg delete "HKU\$sid\Software\Classes\WOW6432Node\CLSID\{$GUID}" /f
reg delete "HKU\$sid\Software\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{$GUID}" /f
reg delete "HKU\$sid`_Classes\CLSID\{$GUID}" /f
reg delete "HKU\$sid`_Classes\WOW6432Node\CLSID\{$GUID}" /f
} else {
if (!(New-Object Security.Principal.WindowsPrincipal ([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)) {
throw 'you are not admin'
}
[String] $GUID = [guid]::NewGuid().ToString()
$guid
$null = reg add "HKU\$sid\Software\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{$GUID}" /ve /t REG_SZ /d $name /f
$null = reg add "HKU\$sid\Software\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{$GUID}" /v "CreatedBy" /t REG_SZ /d "Create-ThisPcPin" /f
$null = reg add "HKU\$sid\Software\Classes\CLSID\{$GUID}" /ve /t REG_SZ /d $name /f
$null = reg add "HKU\$sid\Software\Classes\CLSID\{$GUID}" /v "{305ca226-d286-468e-b848-2b2e8e697b74} 2" /t REG_DWORD /d "4294967295" /f
$null = reg add "HKU\$sid\Software\Classes\CLSID\{$GUID}" /v "CreatedBy" /t REG_SZ /d "Create-ThisPcPin" /f
$null = reg add "HKU\$sid\Software\Classes\CLSID\{$GUID}" /v "DescriptionID" /t REG_DWORD /d "3" /f
$null = reg add "HKU\$sid\Software\Classes\CLSID\{$GUID}" /v "InfoTip" /t REG_SZ /d $path /f
$null = reg add "HKU\$sid\Software\Classes\CLSID\{$GUID}" /v "System.IsPinnedtoNameSpaceTree" /t REG_DWORD /d "1" /f
$null = reg add "HKU\$sid\Software\Classes\CLSID\{$GUID}\DefaultIcon" /ve /t REG_SZ /d "%%SystemRoot%%\System32\shell32.dll,3" /f
$null = reg add "HKU\$sid\Software\Classes\CLSID\{$GUID}\InProcServer32" /ve /t REG_SZ /d "shdocvw.dll" /f
$null = reg add "HKU\$sid\Software\Classes\CLSID\{$GUID}\InProcServer32" /v "ThreadingModel" /t REG_SZ /d "Both" /f
$null = reg add "HKU\$sid\Software\Classes\CLSID\{$GUID}\Instance" /v "CLSID" /t REG_SZ /d "{0afaced1-e828-11d1-9187-b532f1e9575d}" /f
$null = reg add "HKU\$sid\Software\Classes\CLSID\{$GUID}\Instance\InitPropertyBag" /v "Attributes" /t REG_DWORD /d "21" /f
$null = reg add "HKU\$sid\Software\Classes\CLSID\{$GUID}\Instance\InitPropertyBag" /v "Target" /t REG_EXPAND_SZ /d $path /f
$null = reg add "HKU\$sid\Software\Classes\CLSID\{$GUID}\ShellEx\PropertySheetHandlers\tab 1 general" /ve /t REG_SZ /d "{21b22460-3aea-1069-a2dc-08002b30309d}" /f
$null = reg add "HKU\$sid\Software\Classes\CLSID\{$GUID}\ShellEx\PropertySheetHandlers\tab 2 customize" /ve /t REG_SZ /d "{ef43ecfe-2ab9-4632-bf21-58909dd177f0}" /f
$null = reg add "HKU\$sid\Software\Classes\CLSID\{$GUID}\ShellEx\PropertySheetHandlers\tab 3 sharing" /ve /t REG_SZ /d "{f81e9010-6ea4-11ce-a7ff-00aa003ca9f6}" /f
$null = reg add "HKU\$sid\Software\Classes\CLSID\{$GUID}\ShellEx\PropertySheetHandlers\tab 4 security" /ve /t REG_SZ /d "{1f2e5c40-9550-11ce-99d2-00aa006e086c}" /f
$null = reg add "HKU\$sid\Software\Classes\CLSID\{$GUID}\ShellFolder" /v "Attributes" /t REG_DWORD /d "4034920525" /f
$null = reg add "HKU\$sid\Software\Classes\CLSID\{$GUID}\ShellFolder" /v "HideAsDeletePerUser" /t REG_SZ /f
$null = reg add "HKU\$sid\Software\Classes\CLSID\{$GUID}\ShellFolder" /v "WantsFORPARSING" /t REG_SZ /f
$null = reg add "HKU\$sid\Software\Classes\WOW6432Node\CLSID\{$GUID}" /ve /t REG_SZ /d $name /f
$null = reg add "HKU\$sid\Software\Classes\WOW6432Node\CLSID\{$GUID}" /v "{305ca226-d286-468e-b848-2b2e8e697b74} 2" /t REG_DWORD /d "4294967295" /f
$null = reg add "HKU\$sid\Software\Classes\WOW6432Node\CLSID\{$GUID}" /v "CreatedBy" /t REG_SZ /d "Create-ThisPcPin" /f
$null = reg add "HKU\$sid\Software\Classes\WOW6432Node\CLSID\{$GUID}" /v "DescriptionID" /t REG_DWORD /d "3" /f
$null = reg add "HKU\$sid\Software\Classes\WOW6432Node\CLSID\{$GUID}" /v "InfoTip" /t REG_SZ /d $path /f
$null = reg add "HKU\$sid\Software\Classes\WOW6432Node\CLSID\{$GUID}" /v "System.IsPinnedtoNameSpaceTree" /t REG_DWORD /d "1" /f
$null = reg add "HKU\$sid\Software\Classes\WOW6432Node\CLSID\{$GUID}\DefaultIcon" /ve /t REG_SZ /d "%%SystemRoot%%\System32\shell32.dll,3" /f
$null = reg add "HKU\$sid\Software\Classes\WOW6432Node\CLSID\{$GUID}\InProcServer32" /ve /t REG_SZ /d "shdocvw.dll" /f
$null = reg add "HKU\$sid\Software\Classes\WOW6432Node\CLSID\{$GUID}\InProcServer32" /v "ThreadingModel" /t REG_SZ /d "Both" /f
$null = reg add "HKU\$sid\Software\Classes\WOW6432Node\CLSID\{$GUID}\Instance" /v "CLSID" /t REG_SZ /d "{0afaced1-e828-11d1-9187-b532f1e9575d}" /f
$null = reg add "HKU\$sid\Software\Classes\WOW6432Node\CLSID\{$GUID}\Instance\InitPropertyBag" /v "Attributes" /t REG_DWORD /d "21" /f
$null = reg add "HKU\$sid\Software\Classes\WOW6432Node\CLSID\{$GUID}\Instance\InitPropertyBag" /v "Target" /t REG_EXPAND_SZ /d $path /f
$null = reg add "HKU\$sid\Software\Classes\WOW6432Node\CLSID\{$GUID}\ShellEx\PropertySheetHandlers\tab 1 general" /ve /t REG_SZ /d "{21b22460-3aea-1069-a2dc-08002b30309d}" /f
$null = reg add "HKU\$sid\Software\Classes\WOW6432Node\CLSID\{$GUID}\ShellEx\PropertySheetHandlers\tab 2 customize" /ve /t REG_SZ /d "{ef43ecfe-2ab9-4632-bf21-58909dd177f0}" /f
$null = reg add "HKU\$sid\Software\Classes\WOW6432Node\CLSID\{$GUID}\ShellEx\PropertySheetHandlers\tab 3 sharing" /ve /t REG_SZ /d "{f81e9010-6ea4-11ce-a7ff-00aa003ca9f6}" /f
$null = reg add "HKU\$sid\Software\Classes\WOW6432Node\CLSID\{$GUID}\ShellEx\PropertySheetHandlers\tab 4 security" /ve /t REG_SZ /d "{1f2e5c40-9550-11ce-99d2-00aa006e086c}" /f
$null = reg add "HKU\$sid\Software\Classes\WOW6432Node\CLSID\{$GUID}\ShellFolder" /v "Attributes" /t REG_DWORD /d "4034920525" /f
$null = reg add "HKU\$sid\Software\Classes\WOW6432Node\CLSID\{$GUID}\ShellFolder" /v "HideAsDeletePerUser" /t REG_SZ /f
$null = reg add "HKU\$sid\Software\Classes\WOW6432Node\CLSID\{$GUID}\ShellFolder" /v "WantsFORPARSING" /t REG_SZ /f
$null = reg add "HKU\$sid`_Classes\CLSID\{$GUID}" /ve /t REG_SZ /d $name /f
$null = reg add "HKU\$sid`_Classes\CLSID\{$GUID}" /v "{305ca226-d286-468e-b848-2b2e8e697b74} 2" /t REG_DWORD /d "4294967295" /f
$null = reg add "HKU\$sid`_Classes\CLSID\{$GUID}" /v "CreatedBy" /t REG_SZ /d "Create-ThisPcPin" /f
$null = reg add "HKU\$sid`_Classes\CLSID\{$GUID}" /v "DescriptionID" /t REG_DWORD /d "3" /f
$null = reg add "HKU\$sid`_Classes\CLSID\{$GUID}" /v "InfoTip" /t REG_SZ /d $path /f
$null = reg add "HKU\$sid`_Classes\CLSID\{$GUID}" /v "System.IsPinnedtoNameSpaceTree" /t REG_DWORD /d "1" /f
$null = reg add "HKU\$sid`_Classes\CLSID\{$GUID}\DefaultIcon" /ve /t REG_SZ /d "%%SystemRoot%%\System32\shell32.dll,3" /f
$null = reg add "HKU\$sid`_Classes\CLSID\{$GUID}\InProcServer32" /ve /t REG_SZ /d "shdocvw.dll" /f
$null = reg add "HKU\$sid`_Classes\CLSID\{$GUID}\InProcServer32" /v "ThreadingModel" /t REG_SZ /d "Both" /f
$null = reg add "HKU\$sid`_Classes\CLSID\{$GUID}\Instance" /v "CLSID" /t REG_SZ /d "{0afaced1-e828-11d1-9187-b532f1e9575d}" /f
$null = reg add "HKU\$sid`_Classes\CLSID\{$GUID}\Instance\InitPropertyBag" /v "Attributes" /t REG_DWORD /d "21" /f
$null = reg add "HKU\$sid`_Classes\CLSID\{$GUID}\Instance\InitPropertyBag" /v "Target" /t REG_EXPAND_SZ /d $path /f
$null = reg add "HKU\$sid`_Classes\CLSID\{$GUID}\ShellEx\PropertySheetHandlers\tab 1 general" /ve /t REG_SZ /d "{21b22460-3aea-1069-a2dc-08002b30309d}" /f
$null = reg add "HKU\$sid`_Classes\CLSID\{$GUID}\ShellEx\PropertySheetHandlers\tab 2 customize" /ve /t REG_SZ /d "{ef43ecfe-2ab9-4632-bf21-58909dd177f0}" /f
$null = reg add "HKU\$sid`_Classes\CLSID\{$GUID}\ShellEx\PropertySheetHandlers\tab 3 sharing" /ve /t REG_SZ /d "{f81e9010-6ea4-11ce-a7ff-00aa003ca9f6}" /f
$null = reg add "HKU\$sid`_Classes\CLSID\{$GUID}\ShellEx\PropertySheetHandlers\tab 4 security" /ve /t REG_SZ /d "{1f2e5c40-9550-11ce-99d2-00aa006e086c}" /f
$null = reg add "HKU\$sid`_Classes\CLSID\{$GUID}\ShellFolder" /v "Attributes" /t REG_DWORD /d "4034920525" /f
$null = reg add "HKU\$sid`_Classes\CLSID\{$GUID}\ShellFolder" /v "HideAsDeletePerUser" /t REG_SZ /f
$null = reg add "HKU\$sid`_Classes\CLSID\{$GUID}\ShellFolder" /v "WantsFORPARSING" /t REG_SZ /f
$null = reg add "HKU\$sid`_Classes\WOW6432Node\CLSID\{$GUID}" /ve /t REG_SZ /d $name /f
$null = reg add "HKU\$sid`_Classes\WOW6432Node\CLSID\{$GUID}" /v "{305ca226-d286-468e-b848-2b2e8e697b74} 2" /t REG_DWORD /d "4294967295" /f
$null = reg add "HKU\$sid`_Classes\WOW6432Node\CLSID\{$GUID}" /v "CreatedBy" /t REG_SZ /d "Create-ThisPcPin" /f
$null = reg add "HKU\$sid`_Classes\WOW6432Node\CLSID\{$GUID}" /v "DescriptionID" /t REG_DWORD /d "3" /f
$null = reg add "HKU\$sid`_Classes\WOW6432Node\CLSID\{$GUID}" /v "InfoTip" /t REG_SZ /d $path /f
$null = reg add "HKU\$sid`_Classes\WOW6432Node\CLSID\{$GUID}" /v "System.IsPinnedtoNameSpaceTree" /t REG_DWORD /d "1" /f
$null = reg add "HKU\$sid`_Classes\WOW6432Node\CLSID\{$GUID}\DefaultIcon" /ve /t REG_SZ /d "%%SystemRoot%%\System32\shell32.dll,3" /f
$null = reg add "HKU\$sid`_Classes\WOW6432Node\CLSID\{$GUID}\InProcServer32" /ve /t REG_SZ /d "shdocvw.dll" /f
$null = reg add "HKU\$sid`_Classes\WOW6432Node\CLSID\{$GUID}\InProcServer32" /v "ThreadingModel" /t REG_SZ /d "Both" /f
$null = reg add "HKU\$sid`_Classes\WOW6432Node\CLSID\{$GUID}\Instance" /v "CLSID" /t REG_SZ /d "{0afaced1-e828-11d1-9187-b532f1e9575d}" /f
$null = reg add "HKU\$sid`_Classes\WOW6432Node\CLSID\{$GUID}\Instance\InitPropertyBag" /v "Attributes" /t REG_DWORD /d "21" /f
$null = reg add "HKU\$sid`_Classes\WOW6432Node\CLSID\{$GUID}\Instance\InitPropertyBag" /v "Target" /t REG_EXPAND_SZ /d $path /f
$null = reg add "HKU\$sid`_Classes\WOW6432Node\CLSID\{$GUID}\ShellEx\PropertySheetHandlers\tab 1 general" /ve /t REG_SZ /d "{21b22460-3aea-1069-a2dc-08002b30309d}" /f
$null = reg add "HKU\$sid`_Classes\WOW6432Node\CLSID\{$GUID}\ShellEx\PropertySheetHandlers\tab 2 customize" /ve /t REG_SZ /d "{ef43ecfe-2ab9-4632-bf21-58909dd177f0}" /f
$null = reg add "HKU\$sid`_Classes\WOW6432Node\CLSID\{$GUID}\ShellEx\PropertySheetHandlers\tab 3 sharing" /ve /t REG_SZ /d "{f81e9010-6ea4-11ce-a7ff-00aa003ca9f6}" /f
$null = reg add "HKU\$sid`_Classes\WOW6432Node\CLSID\{$GUID}\ShellEx\PropertySheetHandlers\tab 4 security" /ve /t REG_SZ /d "{1f2e5c40-9550-11ce-99d2-00aa006e086c}" /f
$null = reg add "HKU\$sid`_Classes\WOW6432Node\CLSID\{$GUID}\ShellFolder" /v "Attributes" /t REG_DWORD /d "4034920525" /f
$null = reg add "HKU\$sid`_Classes\WOW6432Node\CLSID\{$GUID}\ShellFolder" /v "HideAsDeletePerUser" /t REG_SZ /f
$null = reg add "HKU\$sid`_Classes\WOW6432Node\CLSID\{$GUID}\ShellFolder" /v "WantsFORPARSING" /t REG_SZ /f
}
}