-
Notifications
You must be signed in to change notification settings - Fork 85
/
Remove_Structure.ps1
507 lines (443 loc) · 19.6 KB
/
Remove_Structure.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
#***************************************************************************************************************
# Author: Damien VAN ROBAEYS
# Website: http://www.systanddeploy.com
# Twitter: https://twitter.com/syst_and_deploy
# Purpose: This script will remove context menus added to run quickly files in Windows Sandbox
#***************************************************************************************************************
Function Write_Log
{
param(
$Message_Type,
$Message
)
$MyDate = "[{0:MM/dd/yy} {0:HH:mm:ss}]" -f (Get-Date)
write-host "$MyDate - $Message_Type : $Message"
}
Function Remove_Reg_Item
{
param(
$Reg_Path
)
Write_Log -Message_Type "INFO" -Message "Removing registry path: $Reg_Path"
If(test-path $Reg_Path)
{
Write_Log -Message_Type "SUCCESS" -Message "Following registry path exists: $Reg_Path"
Try
{
Remove-Item -Path $Reg_Path -Recurse
Write_Log -Message_Type "SUCCESS" -Message "$Reg_Path has been removed"
}
Catch
{
Write_Log -Message_Type "ERROR" -Message "$Reg_Path has not been removed"
}
}
Else
{
Write_Log -Message_Type "INFO" -Message "Can not find registry path: $Reg_Path"
}
}
$Current_Folder = split-path $MyInvocation.MyCommand.Path
$ProgData = $env:ProgramData
$Sandbox_Folder = "$ProgData\Run_in_Sandbox"
$Sandbox_Folder = "$ProgData\Run_in_Sandbox"
If (-not (Test-Path $Sandbox_Folder) ) {
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[System.Windows.Forms.MessageBox]::Show("Can not find the folder $Sandbox_Folder")
break
}
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
$Run_As_Admin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
If ($Run_As_Admin -eq $False) {
Write_Log -Message_Type "ERROR" -Message "The script has not been lauched with admin rights"
[System.Windows.Forms.MessageBox]::Show("Please run the tool with admin rights :-)")
break
}
Write_Log -Message_Type "INFO" -Message "The script has been launched with admin rights"
$XML_Config = "$Sandbox_Folder\Sandbox_Config.xml"
$Get_XML_Content = [xml] (Get-Content $XML_Config)
# Check which context menu should be remvoved
$Add_EXE = $Get_XML_Content.Configuration.ContextMenu_EXE
$Add_MSI = $Get_XML_Content.Configuration.ContextMenu_MSI
$Add_PS1 = $Get_XML_Content.Configuration.ContextMenu_PS1
$Add_VBS = $Get_XML_Content.Configuration.ContextMenu_VBS
$Add_ZIP = $Get_XML_Content.Configuration.ContextMenu_ZIP
$Add_Folder = $Get_XML_Content.Configuration.ContextMenu_Folder
$Add_Intunewin = $Get_XML_Content.Configuration.ContextMenu_Intunewin
$Add_MultipleApp = $Get_XML_Content.Configuration.ContextMenu_MultipleApp
$Add_Reg = $Get_XML_Content.Configuration.ContextMenu_Reg
$Add_ISO = $Get_XML_Content.Configuration.ContextMenu_ISO
$Add_PPKG = $Get_XML_Content.Configuration.ContextMenu_PPKG
$Add_HTML = $Get_XML_Content.Configuration.ContextMenu_HTML
$Add_MSIX = $Get_XML_Content.Configuration.ContextMenu_MSIX
$Add_CMD = $Get_XML_Content.Configuration.ContextMenu_CMD
$Add_PDF = $Get_XML_Content.Configuration.ContextMenu_PDF
$List_Drive = get-psdrive | where {$_.Name -eq "HKCR_SD"}
If($List_Drive -ne $null){Remove-PSDrive $List_Drive}
New-PSDrive -PSProvider registry -Root HKEY_CLASSES_ROOT -Name HKCR_SD | out-null
If ($Add_PS1 -eq $True) {
# REMOVE RUN ON PS1
Write-Output "Removing context menu for PS1"
$PS1_Main_Menu = "Run PS1 in Sandbox"
$Windows_Version = (Get-CimInstance -class Win32_OperatingSystem).Caption
If ($Windows_Version -like "*Windows 10*") {
$PS1_Shell_Registry_Key = "HKCR_SD:\SystemFileAssociations\.ps1\Shell"
If (Test-Path "$PS1_Shell_Registry_Key\$PS1_Main_Menu") {
Remove_Reg_Item -Reg_Path "$PS1_Shell_Registry_Key\$PS1_Main_Menu"
}
}
If ($Windows_Version -like "*Windows 11*") {
$Current_User_SID = (Get-ChildItem Registry::\HKEY_USERS | Where-Object { Test-Path "$($_.pspath)\Volatile Environment" } | ForEach-Object { (Get-ItemProperty "$($_.pspath)\Volatile Environment") }).PSParentPath.split("\")[-1] # RUN ON ISO
$HKCU_Classes = "Registry::HKEY_USERS\$Current_User_SID" + "_Classes"
If (Test-Path $HKCU_Classes) {
$Default_PS1_HKCU = "$HKCU_Classes\.ps1"
$rOpenWithProgids_Key = "$Default_PS1_HKCU\rOpenWithProgids"
If (Test-Path $rOpenWithProgids_Key) {
$Get_rOpenWithProgids_Default_Value = (Get-Item "$Default_PS1_HKCU\rOpenWithProgids").Property
ForEach ($Prop in $Get_rOpenWithProgids_Default_Value) {
$Default_HKCU_PS1_Shell_Registry_Key = "$HKCU_Classes\$Prop\Shell"
If (Test-Path $Default_HKCU_PS1_Shell_Registry_Key) {
$Main_Menu_Path = "$Default_HKCU_PS1_Shell_Registry_Key\$PS1_Main_Menu"
Remove_Reg_Item -Reg_Path "$Main_Menu_Path"
}
}
}
$OpenWithProgids_Key = "$Default_PS1_HKCU\OpenWithProgids"
If (Test-Path $OpenWithProgids_Key) {
$Get_OpenWithProgids_Default_Value = (Get-Item $OpenWithProgids_Key).Property
ForEach ($Prop in $Get_OpenWithProgids_Default_Value) {
$Default_HKCU_PS1_Shell_Registry_Key = "$HKCU_Classes\$Prop\Shell"
If (Test-Path $Default_HKCU_PS1_Shell_Registry_Key) {
$Main_Menu_Path = "$Default_HKCU_PS1_Shell_Registry_Key\$PS1_Main_Menu"
Remove_Reg_Item -Reg_Path "$Main_Menu_Path"
}
}
}
# RE%OVING CONTEXT MENU DEPENDING OF THE USERCHOICE
$Current_User_SID = (Get-ChildItem Registry::\HKEY_USERS | Where-Object { Test-Path "$($_.pspath)\Volatile Environment" } | ForEach-Object { (Get-ItemProperty "$($_.pspath)\Volatile Environment") }).PSParentPath.split("\")[-1] # RUN ON ISO
$HKCU = "Registry::HKEY_USERS\$Current_User_SID"
$HKCU_Classes = "Registry::HKEY_USERS\$Current_User_SID" + "_Classes"
If (Test-Path $HKCU) {
$PS1_UserChoice = "$HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.ps1\UserChoice"
$Get_UserChoice = (Get-ItemProperty $PS1_UserChoice).ProgID
$HKCR_UserChoice_Key = "HKCR_SD:\$Get_UserChoice"
$HKCR_UserChoice_Shell = "$HKCR_UserChoice_Key\Shell"
If (Test-Path $HKCR_UserChoice_Shell) {
$HKCR_UserChoice_Label = "$HKCR_UserChoice_Shell\$PS1_Main_Menu"
If (Test-Path $HKCR_UserChoice_Label) {
Remove_Reg_Item -Reg_Path $HKCR_UserChoice_Label
}
}
}
}
}
}
If($Add_Reg -eq $True)
{
# REMOVE RUN ON REG
write-host "Removing context menu for REG"
$Reg_Shell_Registry_Key = "HKCR_SD:\regfile\Shell"
$Reg_Key_Label = "Test reg file in Sandbox"
Remove_Reg_Item -Reg_Path "$REG_Shell_Registry_Key\$Reg_Key_Label"
If(test-path "$REG_Shell_Registry_Key\Test the reg file in Sandbox")
{
Remove_Reg_Item -Reg_Path "$REG_Shell_Registry_Key\Test the reg file in Sandbox"
}
}
If($Add_ISO -eq $True)
{
$ISO_Key_Label = "Extract ISO file in Sandbox"
# REMOVE RUN ON REG from HKCR under Windows.IsoFile
write-host "Removing context menu for ISO"
$ISO_Shell_Registry_Key = "HKCR_SD:\Windows.IsoFile\Shell"
If(test-path "$ISO_Shell_Registry_Key\$ISO_Key_Label")
{
Remove_Reg_Item -Reg_Path "$ISO_Shell_Registry_Key\$ISO_Key_Label"
}
$ISO_Key = "HKCR_SD:\.ISO"
If(test-path $ISO_Key)
{
Write_Log -Message_Type "INFO" -Message "The key HKCR\.ISO exists"
$Get_ISO_Keys = Get-Item $ISO_Key
ForEach($Key in $Get_ISO_Keys)
{
$Get_Properties = $Key.Property
Write_Log -Message_Type "INFO" -Message "Following subkeys found: $Get_Properties"
foreach($Property in $Get_Properties)
{
$Prop = (Get-ItemProperty $ISO_Key)."$Property"
Write_Log -Message_Type "INFO" -Message "Following property found: $Prop"
$ISO_Property_Key = "$HKCR_SD\$Prop"
Write_Log -Message_Type "INFO" -Message "Reg path to test: $ISO_Property_Key"
If(test-path $ISO_Property_Key)
{
Write_Log -Message_Type "INFO" -Message "The following reg path exists: $ISO_Property_Key"
$ISO_Property_Shell = "$ISO_Property_Key\Shell"
If(test-path $ISO_Property_Shell)
{
Write_Log -Message_Type "INFO" -Message "The following reg path exists: $ISO_Property_Shell"
$ISO_Key_Label_Path = "$ISO_Property_Shell\$ISO_Key_Label"
If(test-path $ISO_Key_Label_Path)
{
Remove_Reg_Item -Reg_Path $ISO_Key_Label_Path
}
}
}
Else
{
Write_Log -Message_Type "INFO" -Message "The following reg path does not exist: $ISO_Property_Key"
}
}
}
}
# REMOVE RUN ON REG from HKCU if 7zip exists
$ISO_Shell_HKCU_Registry_Key = "Registry::HKEY_USERS\$Current_User_SID"
$HKCU_Classes = "$ISO_Shell_HKCU_Registry_Key\SOFTWARE\Classes"
$Default_ISO_HKCU = "$HKCU_Classes\.iso"
If(test-path $Default_ISO_HKCU)
{
$Get_Default_Value = (Get-ItemProperty $Default_ISO_HKCU)."(default)"
If($Get_Default_Value -eq "7-Zip.iso")
{
$Default_HKCU_ISO_Shell_Registry_Key = "$HKCU_Classes\$Get_Default_Value\Shell"
$ISO_HKCU_Key_Label_Path = "$Default_HKCU_ISO_Shell_Registry_Key\$ISO_Key_Label"
If(test-path $ISO_HKCU_Key_Label_Path)
{
Remove_Reg_Item -Reg_Path $ISO_HKCU_Key_Label_Path
}
}
}
}
If($Add_MSIX -eq $True)
{
write-host "Removing context menu for MSIX"
$MSIX_Key_Label = "Run MSIX file in Sandbox"
# REMOVE RUN ON REG from HKCR
$MSIX_Shell_Registry_Key = "HKCR_SD:\.msix\OpenWithProgids"
If(test-path $MSIX_Shell_Registry_Key)
{
$Get_Default_Value = (Get-Item $MSIX_Shell_Registry_Key).Property
$MSIX_Shell_Registry = "HKCR_SD:\$Get_Default_Value\Shell"
If(test-path $MSIX_Shell_Registry)
{
$MSIX_Key_Label_Path = "$MSIX_Shell_Registry\$MSIX_Key_Label"
If(test-path $MSIX_Key_Label_Path)
{
Remove_Reg_Item -Reg_Path $MSIX_Key_Label_Path
Remove_Reg_Item -Reg_Path "$MSIX_Shell_Registry\$MSIX_Key_Label"
}
}
}
# Modify value from HKCU
$Current_User_SID = (Get-ChildItem Registry::\HKEY_USERS | Where-Object { Test-Path "$($_.pspath)\Volatile Environment" } | ForEach-Object { (Get-ItemProperty "$($_.pspath)\Volatile Environment")}).PSParentPath.split("\")[-1] # RUN ON ISO
$HKCU_Classes = "Registry::HKEY_USERS\$Current_User_SID" + "_Classes"
If(test-path $HKCU_Classes)
{
$Default_MSIX_HKCU = "$HKCU_Classes\.msix"
$Get_Default_Value = (Get-Item "$Default_MSIX_HKCU\OpenWithProgids").Property
$Default_HKCU_MSIX_Shell_Registry_Key = "$HKCU_Classes\$Get_Default_Value\Shell"
$MSIX_HKCU_Key_Label_Path = "$Default_HKCU_MSIX_Shell_Registry_Key\$MSIX_Key_Label"
If(test-path $MSIX_HKCU_Key_Label_Path)
{
Remove_Reg_Item -Reg_Path "$MSIX_HKCU_Key_Label_Path"
}
}
}
If($Add_PPKG -eq $True)
{
# REMOVE RUN ON PPKG
write-host "Removing context menu for PPKG"
$PPKG_Shell_Registry_Key = "HKCR_SD:\Microsoft.ProvTool.Provisioning.1\Shell"
$PPKG_Key_Label = "Run PPKG file in Sandbox"
Remove_Reg_Item -Reg_Path "$PPKG_Shell_Registry_Key\$PPKG_Key_Label"
}
If($Add_HTML -eq $True)
{
$HTML_Key_Label = "Run this web link in Sandbox"
# RUN ON HTML for Edge
$HTML_Edge_Shell_Registry_Key = "HKCR_SD:\MSEdgeHTM\Shell"
Remove_Reg_Item -Reg_Path "$HTML_Edge_Shell_Registry_Key\$HTML_Key_Label"
# RUN ON HTML for Chrome
$HTML_Chrome_Shell_Registry_Key = "HKCR_SD:\ChromeHTML\Shell"
Remove_Reg_Item -Reg_Path "$HTML_Chrome_Shell_Registry_Key\$HTML_Key_Label"
# RUN ON HTML for IE
$HTML_IE_Shell_Registry_Key = "HKCR_SD:\IE.AssocFile.HTM\Shell"
Remove_Reg_Item -Reg_Path "$HTML_IE_Shell_Registry_Key\$HTML_Key_Label"
# RUN ON URL
$URL_Shell_Registry_Key = "HKCR_SD:\IE.AssocFile.URL\Shell"
$URL_Key_Label_Path = "Run this URL in Sandbox"
# $URL_Key_Label_Path = "Run this web link in Sandbox"
Remove_Reg_Item -Reg_Path "$URL_Shell_Registry_Key\$URL_Key_Label_Path"
}
If($Add_EXE -eq $True)
{
# REMOVE RUN ON EXE
write-host "Removing context menu for PS1"
$EXE_Shell_Registry_Key = "HKCR_SD:\exefile\Shell"
$EXE_Basic_Run = "Run EXE in Sandbox"
Remove_Reg_Item -Reg_Path "$EXE_Shell_Registry_Key\$EXE_Basic_Run"
If(test-path "$EXE_Shell_Registry_Key\Run the EXE in Sandbox")
{
Remove_Reg_Item -Reg_Path "$EXE_Shell_Registry_Key\Run the EXE in Sandbox"
}
}
If($Add_MSI -eq $True)
{
# RUN ON MSI
write-host "Removing context menu for MSI"
$MSI_Shell_Registry_Key = "HKCR_SD:\Msi.Package\Shell"
$MSI_Basic_Run = "Run MSI in Sandbox"
Remove_Reg_Item -Reg_Path "$MSI_Shell_Registry_Key\$MSI_Basic_Run"
If(test-path "$MSI_Shell_Registry_Key\Run the MSI in Sandbox")
{
Remove_Reg_Item -Reg_Path "$MSI_Shell_Registry_Key\Run the MSI in Sandbox"
}
}
If($Add_Folder -eq $True)
{
write-host "Removing context menu for folder"
# Share this folder - Inside the folder
$Folder_Inside_Shell_Registry_Key = "HKCR_SD:\Directory\Background\shell"
$Folder_Inside_Basic_Run = "Share this folder in a Sandbox"
Remove_Reg_Item -Reg_Path "$Folder_Inside_Shell_Registry_Key\$Folder_Inside_Basic_Run"
# Share this folder - Right-click on the folder
$Folder_On_Shell_Registry_Key = "HKCR_SD:\Directory\shell"
$Folder_On_Run = "Share this folder in a Sandbox"
Remove_Reg_Item -Reg_Path "$Folder_On_Shell_Registry_Key\$Folder_On_Run"
}
If($Add_Intunewin -eq $True)
{
# RUN ON Intunewin
write-host "Removing context menu for intunewin"
Remove_Reg_Item -Reg_Path "HKCR_SD:\.intunewin"
}
If($Add_MultipleApp -eq $True)
{
# RUN ON multiple app context menu
write-host "Removing context menu for multiple app"
Remove_Reg_Item -Reg_Path "HKCR_SD:\.sdbapp"
}
If($Add_VBS -eq $True)
{
# REMOVE RUN ON VBS
write-host "Removing context menu for VBS"
$VBS_Shell_Registry_Key = "HKCR_SD:\VBSFile\Shell"
$VBS_Basic_Run = "Run VBS in Sandbox"
$VBS_Parameter_Run = "Run VBS in Sandbox with parameters"
Remove_Reg_Item -Reg_Path "$VBS_Shell_Registry_Key\$VBS_Basic_Run"
Remove_Reg_Item -Reg_Path "$VBS_Shell_Registry_Key\$VBS_Parameter_Run"
If(test-path "$VBS_Shell_Registry_Key\Run the VBS in Sandbox")
{
Remove_Reg_Item -Reg_Path "$VBS_Shell_Registry_Key\Run the VBS in Sandbox"
}
If(test-path "$VBS_Shell_Registry_Key\Run the VBS in Sandbox")
{
Remove_Reg_Item -Reg_Path "$VBS_Shell_Registry_Key\Run the VBS in Sandbox with parameters"
}
}
If($Add_ZIP -eq $True)
{
write-host "Removing context menu for ZIP"
# RUN ON ZIP
$ZIP_Shell_Registry_Key = "HKCR_SD:\CompressedFolder\Shell"
$ZIP_Basic_Run = "Extract ZIP in Sandbox"
Remove_Reg_Item -Reg_Path "$ZIP_Shell_Registry_Key\$ZIP_Basic_Run"
If(test-path "$ZIP_Shell_Registry_Key\Extract ZIP in Sandbox")
{
Remove_Reg_Item -Reg_Path "$ZIP_Shell_Registry_Key\Extract ZIP in Sandbox"
}
# RUN ON ZIP if WinRAR is installed
If(test-path "HKCR_SD:\WinRAR.ZIP\Shell\Extract RAR file in Sandbox")
{
$ZIP_WinRAR_Shell_Registry_Key = "HKCR_SD:\WinRAR.ZIP\Shell"
# Remove_Reg_Item -Reg_Path "$ZIP_WinRAR_Shell_Registry_Key\$ZIP_Basic_Run"
Remove_Reg_Item -Reg_Path "$ZIP_WinRAR_Shell_Registry_Key\Extract RAR file in Sandbox"
}
# 7z
If(test-path "HKCR_SD:\WinRAR.ZIP\Shell\Extract 7z file in Sandbox")
{
$Shell_Registry_Key = "HKCR_SD:\Applications\7zFM.exe\Shell"
# Remove_Reg_Item -Reg_Path "$ZIP_WinRAR_Shell_Registry_Key\$ZIP_Basic_Run"
Remove_Reg_Item -Reg_Path "$Shell_Registry_Key\Extract 7z file in Sandbox"
}
If(test-path "HKCR_SD:\WinRAR.ZIP\Shell\Extract 7z file in Sandbox")
{
$Shell_Registry_Key = "HKCR_SD:\7-Zip.7z\Shell"
# Remove_Reg_Item -Reg_Path "$ZIP_WinRAR_Shell_Registry_Key\$ZIP_Basic_Run"
Remove_Reg_Item -Reg_Path "$Shell_Registry_Key\Extract 7z file in Sandbox"
}
# RAR with 7z
If(test-path "HKCR_SD:\WinRAR.ZIP\Shell\Extract RAR file in Sandbox")
{
$Shell_Registry_Key = "HKCR_SD:\7-Zip.rar\Shell"
# Remove_Reg_Item -Reg_Path "$ZIP_WinRAR_Shell_Registry_Key\$ZIP_Basic_Run"
Remove_Reg_Item -Reg_Path "$Shell_Registry_Key\Extract RAR file in Sandbox"
}
# REMOVE RUN ON 7Z
$7z_Key_Label = "Extract 7z file in Sandbox"
$7z_Shell_Registry_Key = "HKCR_SD:\.7z"
If(test-path $7z_Shell_Registry_Key)
{
$Get_Default_Value = (Get-ItemProperty "HKCR_SD:\.7z")."(default)"
$Default_ZIP_Shell_Registry_Key = "HKCR_SD:\$Get_Default_Value\Shell"
If(test-path $Default_ZIP_Shell_Registry_Key)
{
If(test-path $Default_ZIP_Shell_Registry_Key)
{
Remove_Reg_Item -Reg_Path "$Default_ZIP_Shell_Registry_Key\$7z_Key_Label"
}
}
}
# Checking default zip from HKCU
$Current_User_SID = (Get-ChildItem Registry::\HKEY_USERS | Where-Object { Test-Path "$($_.pspath)\Volatile Environment" } | ForEach-Object { (Get-ItemProperty "$($_.pspath)\Volatile Environment")}).PSParentPath.split("\")[-1] # RUN ON ISO
$HKCU = "Registry::HKEY_USERS\$Current_User_SID"
$HKCU_Classes = "Registry::HKEY_USERS\$Current_User_SID" + "_Classes"
If(test-path $HKCU)
{
$ZIP_UserChoice = "$HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.zip\OpenWithProgids"
$Get_Properties = (get-item $ZIP_UserChoice).property
ForEach($Prop in $Get_Properties)
{
$HKCR_UserChoice_Key = "HKCR_SD:\$Prop"
$HKCR_UserChoice_Key
$HKCR_UserChoice_Shell = "$HKCR_UserChoice_Key\Shell"
If(test-path $HKCR_UserChoice_Shell)
{
$HKCR_UserChoice_Label = "$HKCR_UserChoice_Shell\$ZIP_Basic_Run"
If(!(test-path $HKCR_UserChoice_Label))
{
Remove_Reg_Item -Reg_Path $HKCR_UserChoice_Label
}
}
}
}
}
If($Add_CMD -eq $True)
{
# REMOVE RUN ON CMD
Write-Output "Removing context menu for CMD"
$CMD_Shell_Registry_Key = "HKCR_SD:\cmdfile\Shell"
$CMD_Key_Label = "Run CMD in Sandbox"
If (Test-Path "$CMD_Shell_Registry_Key\$CMD_Key_Label") {
Remove_Reg_Item -Reg_Path "$CMD_Shell_Registry_Key\$CMD_Key_Label"
}
# REMOVE RUN ON BAT
Write-Output "Removing context menu for BAT"
$BAT_Shell_Registry_Key = "HKCR_SD:\batfile\Shell"
$BAT_Key_Label = "Run BAT in Sandbox"
If (Test-Path "$BAT_Shell_Registry_Key\$BAT_Key_Label") {
Remove_Reg_Item -Reg_Path "$BAT_Shell_Registry_Key\$BAT_Key_Label"
}
}
If ($Add_PDF -eq $True)
{
# REMOVE RUN ON CMD
Write-Output "Removing context menu for PDF"
$PDF_Shell_Registry_Key = "HKCR_SD:\SystemFileAssociations\.pdf\Shell"
$PDF_Key_Label = "Open PDF in Sandbox"
If (Test-Path "$PDF_Shell_Registry_Key\$PDF_Key_Label") {
Remove_Reg_Item -Reg_Path "$PDF_Shell_Registry_Key\$PDF_Key_Label"
}
}
If($List_Drive -ne $null){Remove-PSDrive $List_Drive}
Remove-item $Sandbox_Folder -recurse -force