-
Notifications
You must be signed in to change notification settings - Fork 235
Expand file tree
/
Copy pathProgram.cs
More file actions
executable file
·103 lines (92 loc) · 3.59 KB
/
Copy pathProgram.cs
File metadata and controls
executable file
·103 lines (92 loc) · 3.59 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
using System;
using System.Windows.Forms;
using System.DirectoryServices.AccountManagement;
using System.Drawing;
using System.IO;
using Microsoft.Win32;
using System.Collections.Generic;
using System.Linq;
/*
Author: @bitsadmin
Website: https://github.com/bitsadmin
License: BSD 3-Clause
*/
namespace FakeLogonScreen
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// Initialize new screen
LogonScreen s = new LogonScreen();
// Set username
string SID = string.Empty;
try
{
UserPrincipal user = UserPrincipal.Current;
s.Username = user.SamAccountName;
s.DisplayName = user.DisplayName;
SID = user.Sid.Value;
s.Context = user.ContextType;
}
catch (Exception)
{
s.Username = Environment.UserName;
s.Context = ContextType.Machine;
}
// Set background
string imagePath = GetImagePath(SID) ?? @"C:\Windows\Web\Screen\img100.jpg";
if (File.Exists(imagePath))
s.BackgroundImage = Image.FromFile(imagePath);
else
s.BackColor = Color.FromArgb(0, 90, 158);
// Show
Application.Run(s);
}
static string GetImagePath(string SID)
{
string foundImage = null;
try
{
// Open registry, if path exists
string regPath = string.Format(@"SOFTWARE\Microsoft\Windows\CurrentVersion\SystemProtectedUserData\{0}\AnyoneRead\LockScreen", SID);
RegistryKey regLockScreen = Registry.LocalMachine.OpenSubKey(regPath);
if (regLockScreen == null)
return null;
// Obtain lock screen index
string imageOrder = (string)regLockScreen.GetValue(null);
int ord = (int)imageOrder[0];
// A = 65 < N = 78 < Z = 90
// Default image is used
if (ord > 78)
{
string webScreenPath = @"C:\Windows\Web\Screen";
List<string> webScreenFiles = new List<string>(Directory.GetFiles(webScreenPath, "img*"));
string image = string.Format("img{0}", ord + 10 + (90 - ord) * 2);
foundImage = (from name
in webScreenFiles
where name.StartsWith(string.Format(@"{0}\{1}", webScreenPath, image))
select name).SingleOrDefault();
}
// Custom image is used
else
{
string customImagePath = string.Format(@"{0}\Microsoft\Windows\SystemData\{1}\ReadOnly", Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), SID);
string customLockScreenPath = string.Format(@"{0}\LockScreen_{1}", customImagePath, imageOrder[0]);
foundImage = Directory.GetFiles(customLockScreenPath)[0];
}
}
catch(Exception e)
{
Console.WriteLine(e);
}
return foundImage;
}
}
}