-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathCommonFunctions.ps1
More file actions
548 lines (470 loc) · 22.2 KB
/
Copy pathCommonFunctions.ps1
File metadata and controls
548 lines (470 loc) · 22.2 KB
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
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
<#
.SYNOPSIS
DEPRECATED - Legacy common functions file for Run-in-Sandbox
.DESCRIPTION
This file is DEPRECATED and maintained only for backward compatibility.
All functions have been migrated to modular PowerShell modules located in:
Sources/Run_in_Sandbox/Modules/
Module structure:
- Modules/Shared/Environment.psm1 - Global variables and environment settings
- Modules/Shared/Logging.psm1 - Write-LogMessage function
- Modules/Shared/Config.psm1 - Get-Config function
- Modules/Runtime/SevenZip.psm1 - 7-Zip related functions
- Modules/Installer/Registry.psm1 - Registry manipulation functions
- Modules/Installer/Validation.psm1 - Validation and setup functions
.NOTES
This file will be removed in a future version.
Please update any scripts that dot-source this file to use Import-Module instead.
#>
Write-Warning "CommonFunctions.ps1 is DEPRECATED. Please use the modular approach with Import-Module instead."
# Define global variables
$TEMP_Folder = $env:temp
$Log_File = "$TEMP_Folder\RunInSandbox_Install.log"
$Run_in_Sandbox_Folder = "$env:ProgramData\Run_in_Sandbox"
$XML_Config = "$Run_in_Sandbox_Folder\Sandbox_Config.xml"
$Windows_Version = (Get-CimInstance -class Win32_OperatingSystem).Caption
$Current_User_SID = (Get-ChildItem -Path Registry::\HKEY_USERS | Where-Object { Test-Path -Path "$($_.pspath)\Volatile Environment" } | ForEach-Object { (Get-ItemProperty -Path "$($_.pspath)\Volatile Environment") }).PSParentPath.split("\")[-1]
$HKCU = "Registry::HKEY_USERS\$Current_User_SID"
$HKCU_Classes = "Registry::HKEY_USERS\$Current_User_SID" + "_Classes"
$Sandbox_Icon = "$env:ProgramData\Run_in_Sandbox\sandbox.ico"
$Sources = $Current_Folder + "\" + "Sources\*"
$Exported_Keys = @()
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
# Function to write log messages
function Write-LogMessage {
param (
[string]$Message,
[string]$Message_Type
)
$MyDate = "[{0:MM/dd/yy} {0:HH:mm:ss}]" -f (Get-Date)
Add-Content -Path $Log_File -Value "$MyDate - $Message_Type : $Message"
$ForegroundColor = switch ($Message_Type) {
"INFO" { 'White' }
"SUCCESS" { 'Green' }
"WARNING" { 'Yellow' }
"ERROR" { 'DarkRed' }
default { 'White' }
}
Write-Host "$MyDate - $Message_Type : $Message" -ForegroundColor $ForegroundColor
}
# Writes a detailed message to log file only (not displayed to user)
# Use this for detailed registry paths, debug info, etc.
function Write-LogDetail {
param (
[string]$Message,
[string]$Message_Type = "DETAIL"
)
$MyDate = "[{0:MM/dd/yy} {0:HH:mm:ss}]" -f (Get-Date)
Add-Content -Path $Log_File -Value "$MyDate - $Message_Type : $Message"
}
# Function to export registry configuration
function Export-RegConfig {
param (
[string] $Reg_Path,
[string] $Backup_Folder = "$Run_in_Sandbox_Folder\Registry_Backup",
[string] $Type,
[string] $Sub_Reg_Path
)
if ($Exported_Keys -contains $Reg_Path) {
$Exported_Keys.Add($Reg_Path)
} else {
return
}
if (-not (Test-Path $Backup_Folder) ) {
New-Item -ItemType Directory -Path $Backup_Folder -Force | Out-Null
}
Write-LogMessage -Message_Type "INFO" -Message "Exporting registry keys"
$Backup_Path = $Backup_Folder + "\" + "Backup_" + $Type
if ($Sub_Reg_Path) {
$Backup_Path = $Backup_Path + "_" + $Sub_Reg_Path
}
$Backup_Path = $Backup_Path + ".reg"
reg export $Reg_Path $Backup_Path /y > $null 2>&1
# Check if the command ran successfully
if ($?) {
Write-LogMessage -Message_Type "SUCCESS" -Message "Exported `"$Reg_Path`" to `"$Backup_Path`""
} else {
Write-LogMessage -Message_Type "ERROR" -Message "Failed to export `"$Reg_Path`""
}
}
# Function to add a registry item
function Add-RegItem {
param (
[string] $Reg_Path = "Registry::HKEY_CLASSES_ROOT",
[string] $Sub_Reg_Path,
[string] $Type,
[string] $Entry_Name = $Type,
[string] $Info_Type = $Type,
[string] $Key_Label = "Run $Entry_Name in Sandbox",
[string] $RegistryPathsFile = "$Run_in_Sandbox_Folder\RegistryEntries.txt",
[string] $MainMenuLabel,
[switch] $MainMenuSwitch
)
$Base_Registry_Key = "$Reg_Path\$Sub_Reg_Path"
$Shell_Registry_Key = "$Base_Registry_Key\Shell"
$Key_Label_Path = "$Shell_Registry_Key\$Key_Label"
$MainMenuLabel_Path = "$Shell_Registry_Key\$MainMenuLabel"
$Command_Path = "$Key_Label_Path\Command"
$Command_for = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -WindowStyle Hidden -NoProfile -ExecutionPolicy Unrestricted -sta -File C:\\ProgramData\\Run_in_Sandbox\\RunInSandbox.ps1 -Type $Type -ScriptPath `"%V`""
Export-RegConfig -Reg_Path $($Base_Registry_Key.Split("::")[-1]) -Type $Type -Sub_Reg_Path $Sub_Reg_Path -ErrorAction Continue
try {
# Log the root registry path to the specified file
if (-not (Test-Path $RegistryPathsFile) ) {
New-Item -ItemType File -Path $RegistryPathsFile -Force | Out-Null
}
if (-not (Test-Path -Path $Base_Registry_Key) ) {
New-Item -Path $Base_Registry_Key -ErrorAction Stop | Out-Null
}
if (-not (Test-Path -Path $Shell_Registry_Key) ) {
New-Item -Path $Shell_Registry_Key -ErrorAction Stop | Out-Null
}
if ($MainMenuSwitch) {
if ( -not (Test-Path $MainMenuLabel_Path) ) {
New-Item -Path $Shell_Registry_Key -Name $MainMenuLabel -Force | Out-Null
New-ItemProperty -Path $MainMenuLabel_Path -Name "subcommands" -PropertyType String | Out-Null
New-Item -Path $MainMenuLabel_Path -Name "Shell" -Force | Out-Null
New-ItemProperty -Path $MainMenuLabel_Path -Name "icon" -PropertyType String -Value $Sandbox_Icon -ErrorAction Stop | Out-Null
}
$Key_Label_Path = "$MainMenuLabel_Path\Shell\$Key_Label"
$Command_Path = "$Key_Label_Path\Command"
}
if (Test-Path -Path $Key_Label_Path) {
Write-LogDetail -Message "Registry key already exists: $Key_Label_Path"
Write-LogMessage -Message_Type "SUCCESS" -Message "Context menu for $Info_Type has already been added"
Add-Content -Path $RegistryPathsFile -Value $Key_Label_Path
return
}
New-Item -Path $Key_Label_Path -ErrorAction Stop | Out-Null
New-Item -Path $Command_Path -ErrorAction Stop | Out-Null
if (-not $MainMenuSwitch) {
New-ItemProperty -Path $Key_Label_Path -Name "icon" -PropertyType String -Value $Sandbox_Icon -ErrorAction Stop | Out-Null
}
Set-Item -Path $Command_Path -Value $Command_for -Force -ErrorAction Stop | Out-Null
Add-Content -Path $RegistryPathsFile -Value $Key_Label_Path
Write-LogDetail -Message "Created registry key: $Key_Label_Path"
Write-LogDetail -Message "Created command path: $Command_Path"
Write-LogMessage -Message_Type "SUCCESS" -Message "Context menu for `"$Info_Type`" has been added"
} catch {
Write-LogDetail -Message "Failed to create registry key: $Key_Label_Path - Error: $($_.Exception.Message)"
Write-LogMessage -Message_Type "ERROR" -Message "Context menu for $Type could not be added"
}
}
# Function to remove a registry item
function Remove-RegItem {
param (
[string] $Reg_Path = "Registry::HKEY_CLASSES_ROOT",
[Parameter(Mandatory=$true)] [string] $Sub_Reg_Path,
[Parameter(Mandatory=$true)] [string] $Type,
[string] $Entry_Name = $Type,
[string] $Info_Type = $Type,
[string] $Key_Label = "Run $Entry_Name in Sandbox",
[string] $MainMenuLabel,
[switch] $MainMenuSwitch
)
Write-LogMessage -Message_Type "INFO" -Message "Removing context menu for $Type"
$Base_Registry_Key = "$Reg_Path\$Sub_Reg_Path"
$Shell_Registry_Key = "$Base_Registry_Key\Shell"
$Key_Label_Path = "$Shell_Registry_Key\$Key_Label"
if (-not (Test-Path -Path $Key_Label_Path) ) {
if ($Global:DeepClean) {
Write-LogMessage -Message_Type "INFO" -Message "Registry Path for $Type has already been removed by deepclean"
return
}
Write-LogMessage -Message_Type "WARNING" -Message "Could not find path for $Type"
return
}
try {
Write-LogDetail -Message "Removing registry path: $Key_Label_Path"
# Remove the registry path recursively
if (Test-Path -Path $Key_Label_Path) {
Remove-Item -LiteralPath $Key_Label_Path -Recurse -Force -ErrorAction Stop
Write-LogDetail -Message "Successfully removed: $Key_Label_Path"
}
Write-LogMessage -Message_Type "SUCCESS" -Message "Context menu for `"$Info_Type`" has been removed"
} catch {
Write-LogDetail -Message "Failed to remove: $Key_Label_Path - Error: $($_.Exception.Message)"
Write-LogMessage -Message_Type "ERROR" -Message "Context menu for $Type couldn´t be removed"
}
}
function Find-RegistryIconPaths {
param (
[Parameter(Mandatory=$true)] [string]$rootRegistryPath,
[string]$iconValueToMatch = "C:\\ProgramData\\Run_in_Sandbox\\sandbox.ico"
)
# Export the registry at the specified rootRegistryPath
$exportPath = "$env:TEMP\registry_export.reg"
reg export $rootRegistryPath $exportPath /y > $null 2>&1
# Initialize an empty array to store matching paths
$matchingPaths = @()
# Read the exported registry file
$lines = Get-Content -Path $exportPath
# Process each line in the exported registry file
foreach ($line in $lines) {
# Check if the line defines a new key
if ($line -match '^\[([^\]]+)\]$') {
$currentPath = $matches[1]
}
# If the line contains the icon value, add the current path to the list
# If the line contains the icon value, add the current path to the list
if ($line -match '^\s*\"Icon\"=\"([^\"]+)\"$' -and $matches[1] -eq $iconValueToMatch) {
$currentPath = "REGISTRY::$currentPath"
$matchingPaths += $currentPath
}
}
$matchingPaths = $matchingPaths | Sort-Object
return $matchingPaths
}
# Function to find 7-Zip installation on host system
function Find-Host7Zip {
# Try common installation paths
$CommonPaths = @(
"C:\Program Files\7-Zip\7z.exe",
"C:\Program Files (x86)\7-Zip\7z.exe",
"${env:ProgramFiles}\7-Zip\7z.exe",
"${env:ProgramFiles(x86)}\7-Zip\7z.exe"
)
foreach ($Path in $CommonPaths) {
if (Test-Path $Path) {
return $Path
}
}
# Check registry for installation path
try {
$RegPath = Get-ItemProperty -Path "HKLM:\SOFTWARE\7-Zip" -Name "Path" -ErrorAction SilentlyContinue
if ($RegPath -and (Test-Path "$($RegPath.Path)\7z.exe")) {
return "$($RegPath.Path)\7z.exe"
}
} catch {}
# Check PATH environment variable
try {
$7zInPath = Get-Command "7z.exe" -ErrorAction SilentlyContinue
if ($7zInPath) {
return $7zInPath.Source
}
} catch {}
return $null
}
# Function to get latest 7-Zip download URL from GitHub releases
function Get-Latest7ZipDownloadUrl {
try {
$ApiUrl = "https://api.github.com/repos/ip7z/7zip/releases/latest"
$Response = Invoke-RestMethod -Uri $ApiUrl -UseBasicParsing
# Look for x64 MSI installer first, fallback to x86 if needed
$Asset = $Response.assets | Where-Object { $_.name -like "*-x64.msi" -and $_.name -notlike "*extra*" }
if (-not $Asset) {
# Fallback to x86 MSI if x64 not available
$Asset = $Response.assets | Where-Object { $_.name -like "*.msi" -and $_.name -notlike "*extra*" -and $_.name -notlike "*x64*" }
}
if ($Asset) {
return $Asset.browser_download_url
}
} catch {
Write-LogMessage -Message_Type "WARNING" -Message "Failed to get latest 7-Zip version from GitHub: $($_.Exception.Message)"
}
return $null
}
# Function to check if cached 7-Zip installer should be updated
function Test-7ZipCacheAge {
$TempFolder = "$Run_in_Sandbox_Folder\temp"
$CachedInstaller = "$TempFolder\7zSetup.msi"
$VersionFile = "$TempFolder\7zVersion.txt"
# If no cached installer exists, we need to download
if (-not (Test-Path $CachedInstaller)) {
return $true
}
# Check if cache is older than 7 days
$CacheAge = (Get-Date) - (Get-Item $CachedInstaller).LastWriteTime
if ($CacheAge.Days -gt 7) {
Write-LogMessage -Message_Type "INFO" -Message "Cached 7-Zip installer is $($CacheAge.Days) days old, checking for updates"
return $true
}
return $false
}
# Function to download and cache latest 7-Zip installer
function Update-7ZipCache {
param(
[switch]$Force
)
$TempFolder = "$Run_in_Sandbox_Folder\temp"
$CachedInstaller = "$TempFolder\7zSetup.msi"
$VersionFile = "$TempFolder\7zVersion.txt"
# Check if we need to update (unless forced)
if (-not $Force -and -not (Test-7ZipCacheAge)) {
Write-LogMessage -Message_Type "INFO" -Message "Cached 7-Zip installer is recent, skipping update"
return $true
}
# Ensure temp folder exists
if (-not (Test-Path $TempFolder)) {
New-Item -ItemType Directory -Path $TempFolder -Force | Out-Null
}
# Get latest download URL
$DownloadUrl = Get-Latest7ZipDownloadUrl
if (-not $DownloadUrl) {
Write-LogMessage -Message_Type "ERROR" -Message "Could not determine latest 7-Zip download URL"
return $false
}
try {
Write-LogMessage -Message_Type "INFO" -Message "Downloading latest 7-Zip installer from: $DownloadUrl"
Invoke-WebRequest -Uri $DownloadUrl -OutFile $CachedInstaller -UseBasicParsing
# Save download timestamp and URL for tracking
@{
Downloaded = (Get-Date).ToString()
Url = $DownloadUrl
} | ConvertTo-Json | Set-Content $VersionFile
Write-LogMessage -Message_Type "SUCCESS" -Message "7-Zip installer cached successfully"
return $true
} catch {
Write-LogMessage -Message_Type "ERROR" -Message "Failed to download 7-Zip installer: $($_.Exception.Message)"
return $false
}
}
# Function to ensure 7-Zip cache is available and current
function Ensure-7ZipCache {
$TempFolder = "$Run_in_Sandbox_Folder\temp"
$CachedInstaller = "$TempFolder\7zSetup.msi"
# Try to update if needed (network available)
try {
if (Test-7ZipCacheAge) {
Update-7ZipCache
}
} catch {
Write-LogMessage -Message_Type "WARNING" -Message "Could not check for 7-Zip updates, using cached version if available"
}
# Return whether we have a usable cached installer
return (Test-Path $CachedInstaller)
}
# Function to get the configuration from XML
function Get-Config {
if ( [string]::IsNullOrEmpty($XML_Config) ) {
return
}
if (-not (Test-Path -Path $XML_Config) ) {
return
}
$Get_XML_Content = [xml](Get-Content $XML_Config)
$script:Add_EXE = $Get_XML_Content.Configuration.ContextMenu_EXE
$script:Add_MSI = $Get_XML_Content.Configuration.ContextMenu_MSI
$script:Add_PS1 = $Get_XML_Content.Configuration.ContextMenu_PS1
$script:Add_VBS = $Get_XML_Content.Configuration.ContextMenu_VBS
$script:Add_ZIP = $Get_XML_Content.Configuration.ContextMenu_ZIP
$script:Add_Folder = $Get_XML_Content.Configuration.ContextMenu_Folder
$script:Add_Intunewin = $Get_XML_Content.Configuration.ContextMenu_Intunewin
$script:Add_MultipleApp = $Get_XML_Content.Configuration.ContextMenu_MultipleApp
$script:Add_Reg = $Get_XML_Content.Configuration.ContextMenu_Reg
$script:Add_ISO = $Get_XML_Content.Configuration.ContextMenu_ISO
$script:Add_PPKG = $Get_XML_Content.Configuration.ContextMenu_PPKG
$script:Add_HTML = $Get_XML_Content.Configuration.ContextMenu_HTML
$script:Add_MSIX = $Get_XML_Content.Configuration.ContextMenu_MSIX
$script:Add_CMD = $Get_XML_Content.Configuration.ContextMenu_CMD
$script:Add_PDF = $Get_XML_Content.Configuration.ContextMenu_PDF
}
# Function to check if the script is run with admin privileges
function Test-ForAdmin {
$Run_As_Admin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $Run_As_Admin) {
Write-LogMessage -Message_Type "ERROR" -Message "The script has not been launched with admin rights"
[System.Windows.Forms.MessageBox]::Show("Please run the tool with admin rights :-)")
EXIT
}
Write-LogMessage -Message_Type "INFO" -Message "The script has been launched with admin rights"
}
# Function to check for source files
function Test-ForSources {
if (-not (Test-Path -Path $Sources)) {
Write-LogMessage -Message_Type "ERROR" -Message "Sources folder is missing"
[System.Windows.Forms.MessageBox]::Show("It seems you haven´t downloaded all the folder structure.`nThe folder `"Sources`" is missing !!!")
EXIT
}
Write-LogMessage -Message_Type "SUCCESS" -Message "The sources folder exists"
$Check_Sources_Files_Count = (Get-ChildItem -Path "$Current_Folder\Sources\Run_in_Sandbox" -Recurse).count
if ($Check_Sources_Files_Count -lt 25) { # Reduced from 40 to 26 (removed 14 bundled 7zip files)
Write-LogMessage -Message_Type "ERROR" -Message "Some contents are missing"
[System.Windows.Forms.MessageBox]::Show("It seems you haven´t downloaded all the folder structure !!!")
EXIT
}
}
# Function to check if the Windows Sandbox feature is installed
function Test-ForSandbox {
try {
$Is_Sandbox_Installed = (Get-WindowsOptionalFeature -Online -ErrorAction SilentlyContinue | Where-Object { $_.featurename -eq "Containers-DisposableClientVM" }).state
} catch {
if (Test-Path -Path "C:\Windows\System32\WindowsSandbox.exe") {
Write-LogMessage -Message_Type "WARNING" -Message "It looks like you have the `Windows Sandbox` Feature installed, but your `TrustedInstaller` Service is disabled."
Write-LogMessage -Message_Type "WARNING" -Message "The Script will continue, but you should check for issues running Windows Sandbox."
$Is_Sandbox_Installed = "Enabled"
} else {
$Is_Sandbox_Installed = "Disabled"
}
}
if ($Is_Sandbox_Installed -eq "Disabled") {
Write-LogMessage -Message_Type "ERROR" -Message "The feature `Windows Sandbox` is not installed !!!"
[System.Windows.Forms.MessageBox]::Show("The feature `Windows Sandbox` is not installed !!!")
EXIT
}
}
# Function to check if the Sandbox folder exists
function Test-ForSandboxFolder {
if ( [string]::IsNullOrEmpty($Sandbox_Folder) ) {
return
}
if (-not (Test-Path -Path $Sandbox_Folder) ) {
[System.Windows.Forms.MessageBox]::Show("Can not find the folder $Sandbox_Folder")
EXIT
}
}
function Copy-Sources {
try {
Copy-Item -Path $Sources -Destination $env:ProgramData -Force -Recurse | Out-Null
Write-LogMessage -Message_Type "SUCCESS" -Message "Sources have been copied in $env:ProgramData\Run_in_Sandbox"
} catch {
Write-LogMessage -Message_Type "ERROR" -Message "Sources have not been copied in $env:ProgramData\Run_in_Sandbox"
EXIT
}
# Copy CommonFunctions.ps1 to the installation directory so RunInSandbox.ps1 can load it
try {
Copy-Item -Path "$Current_Folder\CommonFunctions.ps1" -Destination "$env:ProgramData\Run_in_Sandbox\" -Force | Out-Null
Write-LogMessage -Message_Type "SUCCESS" -Message "CommonFunctions.ps1 copied to installation directory"
} catch {
Write-LogMessage -Message_Type "ERROR" -Message "Failed to copy CommonFunctions.ps1 to installation directory"
EXIT
}
if (-not (Test-Path -Path "$env:ProgramData\Run_in_Sandbox\RunInSandbox.ps1") ) {
Write-LogMessage -Message_Type "ERROR" -Message "File RunInSandbox.ps1 is missing"
[System.Windows.Forms.MessageBox]::Show("File RunInSandbox.ps1 is missing !!!")
EXIT
}
}
function Unblock-Sources {
$Sources_Unblocked = $False
try {
Get-ChildItem -Path $Run_in_Sandbox_Folder -Recurse | Unblock-File
Write-LogMessage -Message_Type "SUCCESS" -Message "Sources files have been unblocked"
$Sources_Unblocked = $True
} catch {
Write-LogMessage -Message_Type "ERROR" -Message "Sources files have not been unblocked"
EXIT
}
if ($Sources_Unblocked -ne $True) {
Write-LogMessage -Message_Type "ERROR" -Message "Source files could not be unblocked"
[System.Windows.Forms.MessageBox]::Show("Source files could not be unblocked")
EXIT
}
}
function New-Checkpoint {
if (-not $NoCheckpoint) {
$SystemRestoreEnabled = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore" -Name "RPSessionInterval").RPSessionInterval
if ($SystemRestoreEnabled -eq 0) {
Write-LogMessage -Message_Type "WARNING" -Message "System Restore feature is disabled. Enable this to create a System restore point"
} else {
$Checkpoint_Command = '-Command Checkpoint-Computer -Description "Windows_Sandbox_Context_menus" -RestorePointType "MODIFY_SETTINGS" -ErrorAction Stop'
$ReturnValue = Start-Process -FilePath "C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe" -ArgumentList $Checkpoint_Command -Wait -PassThru -WindowStyle Minimized
if ($ReturnValue.ExitCode -eq 0) {
Write-LogMessage -Message_Type "SUCCESS" -Message "Creation of restore point `"Add Windows Sandbox Context menus`""
} else {
Write-LogMessage -Message_Type "ERROR" -Message "Creation of restore point `"Add Windows Sandbox Context menus`" failed."
Write-LogMessage -Message_Type "ERROR" -Message "Press any button to continue anyway."
Read-Host
}
}
}
}