Skip to content

Commit

Permalink
Added context menu entry for running CMD/BAT in Sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
Joly0 committed Apr 4, 2023
1 parent e6793f2 commit 23dc192
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 25 deletions.
37 changes: 34 additions & 3 deletions Add_Structure.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ $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

If (-not (Test-Path "$ProgData\Run_in_Sandbox\RunInSandbox.ps1") ) {
Write_Log -Message_Type "ERROR" -Message "File RunInSandbox.ps1 is missing"
Expand Down Expand Up @@ -187,6 +188,7 @@ Write-Progress -Activity $Progress_Activity -PercentComplete 10


Export_Reg_Config -Reg_Path "exefile" -Backup_Path "$Backup_Folder\Backup_HKRoot_EXEFile.reg"
Export_Reg_Config -Reg_Path "cmdfile" -Backup_Path "$Backup_Folder\Backup_HKRoot_CMDFILE.reg"
Export_Reg_Config -Reg_Path "Microsoft.PowerShellScript.1" -Backup_Path "$Backup_Folder\Backup_HKRoot_PowerShellScript.reg"
Export_Reg_Config -Reg_Path "VBSFile" -Backup_Path "$Backup_Folder\Backup_HKRoot_VBSFile.reg"
Export_Reg_Config -Reg_Path "Msi.Package" -Backup_Path "$Backup_Folder\Backup_HKRoot_Msi.reg"
Expand Down Expand Up @@ -765,7 +767,6 @@ If ($Add_ZIP -eq $True) {
$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"
Expand Down Expand Up @@ -852,10 +853,8 @@ If ($Add_Folder -eq $True) {
Set-Item -Path "$ContextMenu_Folder_Inside\command" -Value $Command_For_Folder_Inside -Force | Out-Null
Write_Log -Message_Type "INFO" -Message "Context menus for folder have been added"


Write-Progress -Activity $Progress_Activity -PercentComplete 85


# Share this folder - Right-click on the folder
$Folder_On_Shell_Registry_Key = "HKCR_SD:\Directory\shell"
# $Folder_On_Run = $Get_Language_File_Content.Folder
Expand All @@ -872,6 +871,38 @@ If ($Add_Folder -eq $True) {
Set-Item -Path "$ContextMenu_Folder_On\command" -Value $Command_For_Folder_On -Force | Out-Null
}

If ($Add_CMD -eq $True) {
# RUN ON CMD
$CMD_Shell_Registry_Key = "HKCR_SD:\cmdfile\Shell"
$CMD_Basic_Run = "Run CMD in Sandbox"
$ContextMenu_Basic_CMD = "$CMD_Shell_Registry_Key\$CMD_Basic_Run"

New-Item -Path $CMD_Shell_Registry_Key -Name $CMD_Basic_Run -Force | Out-Null
New-Item -Path $ContextMenu_Basic_CMD -Name "Command" -Force | Out-Null
# Add Sandbox Icons
New-ItemProperty -Path $ContextMenu_Basic_CMD -Name "icon" -PropertyType String -Value $Sandbox_Icon | Out-Null
$Command_For_CMD = 'C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -WindowStyle Hidden -NoProfile -ExecutionPolicy Unrestricted -sta -File C:\\ProgramData\\Run_in_Sandbox\\RunInSandbox.ps1 -Type CMD -ScriptPath "%V"'
# Set the command path
Set-Item -Path "$ContextMenu_Basic_CMD\command" -Value $Command_For_CMD -Force | Out-Null
Write_Log -Message_Type "INFO" -Message "Context menus for CMD have been added"

Write-Progress -Activity $Progress_Activity -PercentComplete 95

# RUN ON BAT
$BAT_Shell_Registry_Key = "HKCR_SD:\batfile\Shell"
$BAT_Basic_Run = "Run BAT in Sandbox"
$ContextMenu_Basic_BAT = "$BAT_Shell_Registry_Key\$BAT_Basic_Run"

New-Item -Path $BAT_Shell_Registry_Key -Name $BAT_Basic_Run -Force | Out-Null
New-Item -Path $ContextMenu_Basic_BAT -Name "Command" -Force | Out-Null
# Add Sandbox Icons
New-ItemProperty -Path $ContextMenu_Basic_BAT -Name "icon" -PropertyType String -Value $Sandbox_Icon | Out-Null
$Command_For_BAT = 'C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -WindowStyle Hidden -NoProfile -ExecutionPolicy Unrestricted -sta -File C:\\ProgramData\\Run_in_Sandbox\\RunInSandbox.ps1 -Type CMD -ScriptPath "%V"'
# Set the command path
Set-Item -Path "$ContextMenu_Basic_BAT\command" -Value $Command_For_BAT -Force | Out-Null
Write_Log -Message_Type "INFO" -Message "Context menus for BAT have been added"
}

If ($null -ne $List_Drive) { Remove-PSDrive $List_Drive }

Write-Progress -Activity $Progress_Activity -PercentComplete 100
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased


## 2023-03-22
### Added
- Added context menu entry for running CMD/BAT in Sandbox


## 2023-03-21
### Changed
- Readded 7z part and adjusted 7z reg key path
Expand Down
51 changes: 33 additions & 18 deletions Remove_Structure.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ $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

$List_Drive = Get-PSDrive | Where-Object { $_.Name -eq "HKCR_SD" }
If ($null -ne $List_Drive) { Remove-PSDrive $List_Drive }
Expand Down Expand Up @@ -143,10 +144,9 @@ If ($Add_Reg -eq $True) {
Write-Output "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 (Test-Path "$REG_Shell_Registry_Key\$Reg_Key_Label") {
Remove_Reg_Item -Reg_Path "$REG_Shell_Registry_Key\$Reg_Key_Label"
}
}

Expand Down Expand Up @@ -275,10 +275,9 @@ If ($Add_EXE -eq $True) {
Write-Output "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 (Test-Path "$EXE_Shell_Registry_Key\$EXE_Basic_Run") {
Remove_Reg_Item -Reg_Path "$EXE_Shell_Registry_Key\$EXE_Basic_Run"
}
}

Expand All @@ -287,10 +286,9 @@ If ($Add_MSI -eq $True) {
Write-Output "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 (Test-Path "$MSI_Shell_Registry_Key\$MSI_Basic_Run") {
Remove_Reg_Item -Reg_Path "$MSI_Shell_Registry_Key\$MSI_Basic_Run"
}
}

Expand Down Expand Up @@ -325,15 +323,13 @@ If ($Add_VBS -eq $True) {
$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\$VBS_Basic_Run") {
Remove_Reg_Item -Reg_Path "$VBS_Shell_Registry_Key\$VBS_Basic_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 with parameters"
If (Test-Path "$VBS_Shell_Registry_Key\$VBS_Parameter_Run") {
Remove_Reg_Item -Reg_Path "$VBS_Shell_Registry_Key\$VBS_Parameter_Run"
}
}

Expand All @@ -342,10 +338,9 @@ If ($Add_ZIP -eq $True) {
# 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 the ZIP in Sandbox") {
Remove_Reg_Item -Reg_Path "$ZIP_Shell_Registry_Key\Extract the ZIP in Sandbox"
If (Test-Path "$ZIP_Shell_Registry_Key\$ZIP_Basic_Run") {
Remove_Reg_Item -Reg_Path "$ZIP_Shell_Registry_Key\$ZIP_Basic_Run"
}

# RUN ON ZIP if WinRAR is installed
Expand Down Expand Up @@ -394,6 +389,26 @@ If ($Add_ZIP -eq $True) {
}
}

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 ($null -ne $List_Drive) { Remove-PSDrive $List_Drive }

Remove-Item $Sandbox_Folder -Recurse -Force
9 changes: 5 additions & 4 deletions Sources/Run_in_Sandbox/Sandbox_Config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
<ContextMenu_MSI>True</ContextMenu_MSI> <!-- Choose to add or not context menu to run MSI in Sandbox. True or False -->
<ContextMenu_PS1>True</ContextMenu_PS1> <!-- Choose to add or not context menu to run PS1 in Sandbox. True or False -->
<ContextMenu_VBS>True</ContextMenu_VBS> <!-- Choose to add or not context menu to run VBS in Sandbox. True or False -->
<ContextMenu_ZIP>True</ContextMenu_ZIP> <!-- Choose to add or not context menu to extract ZIP in Sandbox. True or False -->
<ContextMenu_ZIP>True</ContextMenu_ZIP> <!-- Choose to add or not context menu to extract ZIP/7z in Sandbox. True or False -->
<ContextMenu_Folder>True</ContextMenu_Folder> <!-- Choose to add or not context menu to share folder content in Sandbox. True or False -->
<ContextMenu_Intunewin>True</ContextMenu_Intunewin> <!-- Choose to add or not context menu to run Intunewin in Sandbox. True or False -->
<ContextMenu_MultipleApp>True</ContextMenu_MultipleApp> <!-- Choose to add or not context menu to run Intunewin in Sandbox. True or False -->
<ContextMenu_Reg>True</ContextMenu_Reg> <!-- Choose to add or not context menu to run Intunewin in Sandbox. True or False -->
<ContextMenu_MultipleApp>True</ContextMenu_MultipleApp> <!-- Choose to add or not context menu to run Multiple Apps in Sandbox. True or False -->
<ContextMenu_Reg>True</ContextMenu_Reg> <!-- Choose to add or not context menu to run Reg in Sandbox. True or False -->
<ContextMenu_ISO>True</ContextMenu_ISO> <!-- Choose to add or not context menu to extract ISO in Sandbox. True or False -->
<ContextMenu_PPKG>True</ContextMenu_PPKG> <!-- Choose to add or not context menu to run PPKG in Sandbox. True or False -->
<ContextMenu_HTML>True</ContextMenu_HTML> <!-- Choose to add or not context menu to run HTML in Sandbox. True or False -->
<ContextMenu_MSIX>True</ContextMenu_MSIX> <!-- Choose to add or not context menu to run HTML in Sandbox. True or False -->
<ContextMenu_MSIX>True</ContextMenu_MSIX> <!-- Choose to add or not context menu to run MSIX/MSIXBundle in Sandbox. True or False -->
<ContextMenu_CMD>True</ContextMenu_CMD> <!-- Choose to add or not context menu to run CMD in Sandbox. True or False -->
<WSB_Cleanup>True</WSB_Cleanup> <!-- Choose to cleanup left-over files after sandbox has been closed. True or False -->
</Configuration>

0 comments on commit 23dc192

Please sign in to comment.