Skip to content

Commit 2476726

Browse files
rayfoRaymond Fowkes
andauthored
Handle Mark of the Web on downloaded files. (#41)
Co-authored-by: Raymond Fowkes <REFowkes@frontier.com>
1 parent efe1b4c commit 2476726

18 files changed

Lines changed: 187 additions & 0 deletions

src/BETA/Generate-PmuRegFile.bat

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ REM The powershell script has the same path and base name as this batch script.
55
set _PATH="%~dpn0.ps1"
66
set _ARGS=%*
77

8+
REM Detect, warn, and remove Mark of the Web.
9+
(more < "%~dpn0.ps1:Zone.Identifier") >nul 2>nul && (
10+
echo Unblocking downloaded PowerShell script: %~n0.ps1
11+
echo https://github.com/microsoft/MSO-Scripts/wiki/Frequently-Asked-Questions#policy
12+
echo:>"%~dpn0.ps1:Zone.Identifier"
13+
powershell unblock-file '%~dpn0.ps1' 2>nul
14+
echo:
15+
)
16+
817
REM Escape spaces and quotes for use with: -command
918
set _CMD=-command %_PATH: =` %
1019
if defined _ARGS set _CMD=%_CMD% %_ARGS:"='%

src/BETA/TraceEdgeChrome.bat

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ REM The powershell script has the same path and base name as this batch script.
55
set _PATH="%~dpn0.ps1"
66
set _ARGS=%*
77

8+
REM Detect, warn, and remove Mark of the Web.
9+
set TraceThis=%~n0.ps1
10+
set Include=..\INCLUDE*.ps1
11+
(more < "%~dp0%TraceThis%:Zone.Identifier") >nul 2>nul && (
12+
echo Unblocking downloaded PowerShell scripts: %TraceThis%, %Include%
13+
echo https://github.com/microsoft/MSO-Scripts/wiki/Frequently-Asked-Questions#policy
14+
for %%f in ("%~dp0%TraceThis%","%~dp0%Include%") do echo %%~nxf & echo:>"%%~f:Zone.Identifier"
15+
echo:
16+
)
17+
818
REM Escape spaces and quotes for use with: -command
919
set _CMD=-command %_PATH: =` %
1020
if defined _ARGS set _CMD=%_CMD% %_ARGS:"='%

src/BETA/TraceNetwork.bat

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ REM The powershell script has the same path and base name as this batch script.
55
set _PATH="%~dpn0.ps1"
66
set _ARGS=%*
77

8+
REM Detect, warn, and remove Mark of the Web.
9+
set TraceThis=%~n0.ps1
10+
set Include=..\INCLUDE*.ps1
11+
(more < "%~dp0%TraceThis%:Zone.Identifier") >nul 2>nul && (
12+
echo Unblocking downloaded PowerShell scripts: %TraceThis%, %Include%
13+
echo https://github.com/microsoft/MSO-Scripts/wiki/Frequently-Asked-Questions#policy
14+
for %%f in ("%~dp0%TraceThis%","%~dp0%Include%") do echo %%~nxf & echo:>"%%~f:Zone.Identifier"
15+
echo:
16+
)
17+
818
REM Escape spaces and quotes for use with: -command
919
set _CMD=-command %_PATH: =` %
1020
if defined _ARGS set _CMD=%_CMD% %_ARGS:"='%

src/BETA/TracePMC.bat

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ REM The powershell script has the same path and base name as this batch script.
55
set _PATH="%~dpn0.ps1"
66
set _ARGS=%*
77

8+
REM Detect, warn, and remove Mark of the Web.
9+
set TraceThis=%~n0.ps1
10+
set Include=..\INCLUDE*.ps1
11+
(more < "%~dp0%TraceThis%:Zone.Identifier") >nul 2>nul && (
12+
echo Unblocking downloaded PowerShell scripts: %TraceThis%, %Include%
13+
echo https://github.com/microsoft/MSO-Scripts/wiki/Frequently-Asked-Questions#policy
14+
for %%f in ("%~dp0%TraceThis%","%~dp0%Include%") do echo %%~nxf & echo:>"%%~f:Zone.Identifier"
15+
echo:
16+
)
17+
818
REM Escape spaces and quotes for use with: -command
919
set _CMD=-command %_PATH: =` %
1020
if defined _ARGS set _CMD=%_CMD% %_ARGS:"='%

src/INCLUDE.ps1

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3507,13 +3507,33 @@ function CheckLanguageMode
35073507
}
35083508

35093509

3510+
<#
3511+
If the given file is blocked with Mark of the Web, then unblock all related .ps1 files.
3512+
#>
3513+
function CheckMarkOfTheWeb
3514+
{
3515+
Param (
3516+
$Path
3517+
)
3518+
if ($Path -and (Get-Item -Path $Path -Stream 'Zone.Identifier' -ErrorAction:SilentlyContinue))
3519+
{
3520+
Write-Warn 'Unblocking all downloaded PowerShell scripts in this folder: *.ps1'
3521+
$Path = Split-Path -Parent -Path $Path
3522+
Get-ChildItem -Path $Path -Recurse -Filter '*.ps1' | Unblock-File -ErrorAction:SilentlyContinue -Verbose:(DoVerbose)
3523+
Write-Warn
3524+
}
3525+
}
3526+
3527+
35103528
<#
35113529
These actions must occur immediately upon load.
35123530
#>
35133531
# Main
35143532

35153533
CheckLanguageMode
35163534

3535+
if ($Host.Version.Major -gt 2) { CheckMarkOfTheWeb $MyInvocation.MyCommand.Path }
3536+
35173537
# Native enum doesn't exist until PS v5.0
35183538
Add-Type -TypeDefinition @"
35193539
public enum ResultValue

src/ResetWPA.bat

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ REM The powershell script has the same path and base name as this batch script.
55
set _PATH="%~dpn0.ps1"
66
set _ARGS=%*
77

8+
REM Detect, warn, and remove Mark of the Web.
9+
(more < "%~dpn0.ps1:Zone.Identifier") >nul 2>nul && (
10+
echo Unblocking downloaded PowerShell script: %~n0.ps1
11+
echo https://github.com/microsoft/MSO-Scripts/wiki/Frequently-Asked-Questions#policy
12+
echo:>"%~dpn0.ps1:Zone.Identifier"
13+
powershell unblock-file '%~dpn0.ps1' 2>nul
14+
echo:
15+
)
16+
817
REM Escape spaces and quotes for use with: -command
918
set _CMD=-command %_PATH: =` %
1019
if defined _ARGS set _CMD=%_CMD% %_ARGS:"='%

src/SymbolScan.bat

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ REM The powershell script has the same path and base name as this batch script.
55
set _PATH="%~dpn0.ps1"
66
set _ARGS=%*
77

8+
REM Detect, warn, and remove Mark of the Web.
9+
(more < "%~dpn0.ps1:Zone.Identifier") >nul 2>nul && (
10+
echo Unblocking downloaded PowerShell script: %~n0.ps1
11+
echo https://github.com/microsoft/MSO-Scripts/wiki/Frequently-Asked-Questions#policy
12+
echo:>"%~dpn0.ps1:Zone.Identifier"
13+
powershell unblock-file '%~dpn0.ps1' 2>nul
14+
echo:
15+
)
16+
817
REM Escape spaces and quotes for use with: -command
918
set _CMD=-command %_PATH: =` %
1019
if defined _ARGS set _CMD=%_CMD% %_ARGS:"='%

src/TraceCPU.bat

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ REM The powershell script has the same path and base name as this batch script.
55
set _PATH="%~dpn0.ps1"
66
set _ARGS=%*
77

8+
REM Detect, warn, and remove Mark of the Web.
9+
set TraceThis=%~n0.ps1
10+
set Include=INCLUDE*.ps1
11+
(more < "%~dp0%TraceThis%:Zone.Identifier") >nul 2>nul && (
12+
echo Unblocking downloaded PowerShell scripts: %TraceThis%, %Include%
13+
echo https://github.com/microsoft/MSO-Scripts/wiki/Frequently-Asked-Questions#policy
14+
for %%f in ("%~dp0%TraceThis%","%~dp0%Include%") do echo %%~nxf & echo:>"%%~f:Zone.Identifier"
15+
echo:
16+
)
17+
818
REM Escape spaces and quotes for use with: -command
919
set _CMD=-command %_PATH: =` %
1020
if defined _ARGS set _CMD=%_CMD% %_ARGS:"='%

src/TraceFileDiskIO.bat

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ REM The powershell script has the same path and base name as this batch script.
55
set _PATH="%~dpn0.ps1"
66
set _ARGS=%*
77

8+
REM Detect, warn, and remove Mark of the Web.
9+
set TraceThis=%~n0.ps1
10+
set Include=INCLUDE*.ps1
11+
(more < "%~dp0%TraceThis%:Zone.Identifier") >nul 2>nul && (
12+
echo Unblocking downloaded PowerShell scripts: %TraceThis%, %Include%
13+
echo https://github.com/microsoft/MSO-Scripts/wiki/Frequently-Asked-Questions#policy
14+
for %%f in ("%~dp0%TraceThis%","%~dp0%Include%") do echo %%~nxf & echo:>"%%~f:Zone.Identifier"
15+
echo:
16+
)
17+
818
REM Escape spaces and quotes for use with: -command
919
set _CMD=-command %_PATH: =` %
1020
if defined _ARGS set _CMD=%_CMD% %_ARGS:"='%

src/TraceHandles.bat

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ REM The powershell script has the same path and base name as this batch script.
55
set _PATH="%~dpn0.ps1"
66
set _ARGS=%*
77

8+
REM Detect, warn, and remove Mark of the Web.
9+
set TraceThis=%~n0.ps1
10+
set Include=INCLUDE*.ps1
11+
(more < "%~dp0%TraceThis%:Zone.Identifier") >nul 2>nul && (
12+
echo Unblocking downloaded PowerShell scripts: %TraceThis%, %Include%
13+
echo https://github.com/microsoft/MSO-Scripts/wiki/Frequently-Asked-Questions#policy
14+
for %%f in ("%~dp0%TraceThis%","%~dp0%Include%") do echo %%~nxf & echo:>"%%~f:Zone.Identifier"
15+
echo:
16+
)
17+
818
REM Escape spaces and quotes for use with: -command
919
set _CMD=-command %_PATH: =` %
1020
if defined _ARGS set _CMD=%_CMD% %_ARGS:"='%

0 commit comments

Comments
 (0)