-
Notifications
You must be signed in to change notification settings - Fork 3
/
Lock_screen.ps1
95 lines (75 loc) · 4.7 KB
/
Lock_screen.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
[System.Reflection.Assembly]::LoadWithPartialName('presentationframework') | out-null
[System.Reflection.Assembly]::LoadFrom('assembly\MahApps.Metro.dll') | out-null
[System.Reflection.Assembly]::LoadFrom('assembly\MahApps.Metro.IconPacks.dll') | out-null
function LoadXml ($global:filename)
{
$XamlLoader=(New-Object System.Xml.XmlDocument)
$XamlLoader.Load($filename)
return $XamlLoader
}
# Load MainWindow
$XamlMainWindow=LoadXml("Lock_screen.xaml")
$Reader=(New-Object System.Xml.XmlNodeReader $XamlMainWindow)
$Form=[Windows.Markup.XamlReader]::Load($Reader)
$Enter_TS = $Form.findname("Enter_TS")
$Typed_PWD = $Form.findname("Typed_PWD")
$PWD_Status = $Form.findname("PWD_Status")
# Add custom type to hide the taskbar
# Thanks to https://stackoverflow.com/questions/25499393/make-my-wpf-application-full-screen-cover-taskbar-and-title-bar-of-window
$CSharpSource = @"
using System;
using System.Runtime.InteropServices;
public class Taskbar
{
[DllImport("user32.dll")]
private static extern int FindWindow(string className, string windowText);
[DllImport("user32.dll")]
private static extern int ShowWindow(int hwnd, int command);
private const int SW_HIDE = 0;
private const int SW_SHOW = 1;
protected static int Handle
{
get
{
return FindWindow("Shell_TrayWnd", "");
}
}
private Taskbar()
{
// hide ctor
}
public static void Show()
{
ShowWindow(Handle, SW_SHOW);
}
public static void Hide()
{
ShowWindow(Handle, SW_HIDE);
}
}
"@
Add-Type -ReferencedAssemblies 'System', 'System.Runtime.InteropServices' -TypeDefinition $CSharpSource -Language CSharp
powershell .\Set_CtrlAltDel.ps1 -DisableAll
$IT_PWD = "toto"
$Enter_TS.Add_Click({
$Script:Enter_PWD = $Typed_PWD.Password
If($Enter_PWD -ne "")
{
If($Enter_PWD -eq $IT_PWD)
{
$Script:Password_Status = $True
powershell .\Set_CtrlAltDel.ps1 -EnableAll
[Taskbar]::Show()
$Form.Close()
}
Else
{
$PWD_Status.Content = "Bad password !!!"
}
}
Else
{
[System.Windows.Forms.MessageBox]::Show("Please type a Task sequence password", "Oops, Task Sequence error")
}
})
$Form.ShowDialog() | Out-Null