This repository has been archived by the owner on May 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathBlueScreen.ps1
77 lines (62 loc) · 2.36 KB
/
BlueScreen.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
<#
.Synopsis
Installs a blue screen screensaver that mimics the Windows 8 system fault blue screen.
.DESCRIPTION
Installs a blue screen screensaver that mimics the Windows 8 system fault blue screen. This cmdlet
compiles a custom C# PowerShell SCR file to the system directory that can be used to host any PowerShell
script. The PowerShell script is responsible for displaying the screen saver.
You must run this cmdlet from an elevated PowerShell host.
.EXAMPLE
Install-BlueScreenSaver
#>
function Install-BlueScreenSaver
{
$CSharp =
'
using System;
using System.Windows.Forms;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
public class Program
{
static void Main(string[] args)
{
using (var runSpace = RunspaceFactory.CreateRunspace())
{
runSpace.Open();
using (var pipeline = runSpace.CreatePipeline("C:\\windows\\System32\\ScreenSaver.ps1"))
{
pipeline.Invoke();
}
}
}
}
'
$tmpFile = [IO.Path]::GetTempFileName() + ".cs"
$tempDir = [IO.Path]::GetTempPath()
$ScreenSaverScript = Join-Path (Split-Path $PSCommandPath) "ScreenSaver.ps1"
$bsodPath = Join-Path $tempDir "bluescreen.exe"
Out-File -FilePath $tmpFile -InputObject $CSharp
Start-Process -FilePath C:\windows\Microsoft.NET\Framework\v4.0.30319\csc.exe -ArgumentList "/out:$bsodPath","/r:`"C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\3.0\System.Management.Automation.dll`"",$tmpFile -Wait -NoNewWindow
1..10 | % {
Start-Sleep -Milliseconds 500
if (Test-Path $bsodPath)
{
break
}
}
if (-not (Test-Path $bsodPath))
{
throw new-Object -TypeName System.Exception -ArgumentList "Failed to compile bluescreen.scr"
}
Rename-Item $bsodPath "bluescreen.scr"
$System32 = Join-Path $env:SystemRoot "System32"
Copy-Item $bsodPath (Join-Path $System32 "bluescreen.scr")
Copy-Item $ScreenSaverScript (Join-Path $System32 "ScreenSaver.ps1")
if ($env:PROCESSOR_ARCHITECTURE -eq "AMD64")
{
$System32 = Join-Path $env:SystemRoot "SysWow64"
Copy-Item $bsodPath (Join-Path $System32 "bluescreen.scr")
}
Remove-Item $bsodPath
}