Skip to content

Commit 6ab9896

Browse files
Reworked login adding to reg
Moved Classes LIB to keep stuff nice Added /?
1 parent b0c2341 commit 6ab9896

8 files changed

Lines changed: 153 additions & 96 deletions

File tree

AutoLoginBuilder/AutoLoginBuilder.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<Reference Include="System.Xml" />
6565
</ItemGroup>
6666
<ItemGroup>
67-
<Compile Include="CMDCli.cs" />
67+
<Compile Include="Lib\CMDCli.cs" />
6868
<Compile Include="Form1.cs">
6969
<SubType>Form</SubType>
7070
</Compile>
@@ -73,7 +73,7 @@
7373
</Compile>
7474
<Compile Include="Program.cs" />
7575
<Compile Include="Properties\AssemblyInfo.cs" />
76-
<Compile Include="Worker.cs" />
76+
<Compile Include="Lib\Worker.cs" />
7777
<EmbeddedResource Include="Form1.resx">
7878
<DependentUpon>Form1.cs</DependentUpon>
7979
</EmbeddedResource>

AutoLoginBuilder/CMDCli.cs

Lines changed: 0 additions & 54 deletions
This file was deleted.

AutoLoginBuilder/Form1.Designer.cs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AutoLoginBuilder/Form1.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,33 @@ public partial class Form1 : Form
77
{
88
string[] args = Environment.GetCommandLineArgs();
99
Worker wkr = new Worker();
10-
char p = '"';
10+
1111
public Form1()
1212
{
1313
InitializeComponent();
1414
}
15-
15+
1616
private void RemoveButton_Click(object sender, EventArgs e)
1717
{
18-
wkr.ExecuteCommand("REG ADD "+p+"HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon"+p+" /v AutoAdminLogon /t REG_SZ /d 0 /f /reg:64");
19-
wkr.ExecuteCommand("REG ADD " + p + "HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon" + p + " /v DefaultUserName /t REG_SZ /d "+p+p+" /f /reg:64");
20-
wkr.ExecuteCommand("REG ADD " + p + "HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon" + p + " /v DefaultDomainName /t REG_SZ /d " + p + p + " /f /reg:64");
21-
wkr.ExecuteCommand("REG ADD "+p+"HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon"+p+" /v DefaultPassword /t REG_SZ /d "+p+p+" /f /reg:64");
18+
int success = wkr.autoLoginCommand();
2219
}
2320

2421
private void BuilderButtonClick_Click(object sender, EventArgs e)
2522
{
26-
wkr.ExecuteCommand("REG ADD " + p + "HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon" + p + " /v AutoAdminLogon /t REG_SZ /d 1 /f /reg:64");
27-
wkr.ExecuteCommand("REG ADD " + p + "HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon" + p + " /v DefaultUserName /t REG_SZ /d " + UsernameTextBox.Text + " /f /reg:64");
28-
wkr.ExecuteCommand("REG ADD " + p + "HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon" + p + " /v DefaultDomainName /t REG_SZ /d " + DomainTextBox.Text + " /f /reg:64");
29-
wkr.ExecuteCommand("REG ADD " + p + "HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon" + p + " /v DefaultPassword /t REG_SZ /d " + PasswordTextBox.Text + " /f /reg:64");
23+
int success = wkr.autoLoginCommand(UsernameTextBox.Text, PasswordTextBox.Text, DomainTextBox.Text);
3024
}
31-
3225

3326
private void Form1_Load(object sender, EventArgs e)
3427
{
35-
3628
PasswordTextBox.PasswordChar = '*';
3729
string[] strArr = wkr.defaultDomain(System.Security.Principal.WindowsIdentity.GetCurrent().Name);
3830
UsernameTextBox.Text = strArr[1];
3931
DomainTextBox.Text = strArr[0];
4032
}
4133

34+
private void DomainTextBox_TextChanged(object sender, EventArgs e)
35+
{
36+
37+
}
4238
}
4339
}

AutoLoginBuilder/Lib/CMDCli.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
3+
namespace AutoLoginBuilder
4+
{
5+
class CMDCli
6+
{
7+
Worker wkr = new Worker();
8+
public void arguments(string[] args)
9+
{
10+
if (args[0] == "remove")
11+
{
12+
remover();
13+
}
14+
else if (args[0] == @"/?")
15+
{
16+
Console.WriteLine("CMD : Results");
17+
Console.WriteLine("================================================================");
18+
Console.WriteLine("================================================================");
19+
Console.WriteLine("AutoLoginBuilder.exe remove : WILL REMOVE AUTOLOGIN");
20+
Console.WriteLine("AutoLoginBuilder.exe USERNAME PASSWORD : Will add Auto Login for local users");
21+
Console.WriteLine("AutoLoginBuilder.exe DOMAIN USERNAME PASSWORD : Will add Auto Login for Domain Users");
22+
Console.WriteLine("================================================================");
23+
Console.WriteLine("================================================================");
24+
}
25+
else if (args.Length == 2)
26+
{
27+
adderNoDomain(args[0], args[1]);
28+
}
29+
else if(args.Length == 3)
30+
{
31+
adder(args[0], args[1], args[2]);
32+
}
33+
else
34+
{
35+
throw new ArgumentOutOfRangeException("num2 > double.MaxValue - num1.");
36+
}
37+
}
38+
private void adderNoDomain(string username,string password)
39+
{
40+
wkr.autoLoginCommand(username, password);
41+
}
42+
private void adder(string domain,string username,string password)
43+
{
44+
wkr.autoLoginCommand(username, password, domain);
45+
}
46+
private void remover()
47+
{
48+
wkr.autoLoginCommand();
49+
}
50+
}
51+
}

AutoLoginBuilder/Lib/Worker.cs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using Microsoft.Win32;
2+
using System;
3+
4+
namespace AutoLoginBuilder
5+
{
6+
class Worker
7+
{
8+
9+
/// <summary>
10+
/// Adds autolin for user of your choice provide it with username, password and domain to create auto login set everything to blank if removing
11+
/// </summary>
12+
/// <param name="username">Username For Auto Logged in user if removing leave to blank</param>
13+
/// <param name="password">Password For Auto Logged in user if removing leave to blank</param>
14+
/// <param name="domain">Domain For Auto Logged in user if removing leave to blank</param>
15+
/// <returns>
16+
/// 1 for error
17+
/// 0 for success
18+
/// </returns>
19+
public int autoLoginCommand(string username = null, string password = null, string domain = null)
20+
{
21+
try
22+
{
23+
string winLogin = @"Software\Microsoft\Windows NT\CurrentVersion\Winlogon";
24+
RegistryKey key;
25+
key = Registry.LocalMachine.OpenSubKey(winLogin, true);
26+
if (username == null)
27+
{
28+
if (key != null)
29+
{
30+
key.SetValue("AutoAdminLogon", "0", RegistryValueKind.String);
31+
key.SetValue("DefaultUserName", "", RegistryValueKind.String);
32+
key.SetValue("DefaultDomainName", "", RegistryValueKind.String);
33+
key.SetValue("DefaultPassword", "", RegistryValueKind.String);
34+
key.Close();
35+
}
36+
}
37+
else if(username != null && password != null)
38+
{
39+
if (key != null)
40+
{
41+
key.SetValue("AutoAdminLogon", "1", RegistryValueKind.String);
42+
key.SetValue("DefaultUserName", username, RegistryValueKind.String);
43+
key.SetValue("DefaultDomainName", "", RegistryValueKind.String);
44+
key.SetValue("DefaultPassword", password, RegistryValueKind.String);
45+
key.Close();
46+
}
47+
}
48+
else
49+
{
50+
if (key != null)
51+
{
52+
key.SetValue("AutoAdminLogon", "1", RegistryValueKind.String);
53+
key.SetValue("DefaultUserName", username, RegistryValueKind.String);
54+
key.SetValue("DefaultDomainName", domain, RegistryValueKind.String);
55+
key.SetValue("DefaultPassword", password, RegistryValueKind.String);
56+
key.Close();
57+
}
58+
}
59+
return 0;
60+
}
61+
catch
62+
{
63+
return 1;
64+
}
65+
}
66+
67+
public string[] defaultDomain(string user)
68+
{
69+
char p = '\\';
70+
string[] domainSplit = user.Split(p);
71+
return domainSplit;
72+
}
73+
}
74+
}

AutoLoginBuilder/Program.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,23 @@ static void Main(string[] args)
2121
else
2222
{
2323
CMDCli cmd = new CMDCli();
24-
cmd.arguments(args);
24+
if (args[0] == @"/?")
25+
{
26+
MessageBox.Show(
27+
"CMD : Results" + "\n" +
28+
"==============================================" + "\n" +
29+
"==============================================" + "\n" +
30+
"AutoLoginBuilder.exe remove : WILL REMOVE AUTOLOGIN" + "\n" +
31+
"AutoLoginBuilder.exe USERNAME PASSWORD : Will add Auto Login for local users" + "\n" +
32+
"AutoLoginBuilder.exe DOMAIN USERNAME PASSWORD : Will add Auto Login for Domain Users" + "\n" +
33+
"==============================================" + "\n" +
34+
"==============================================");
35+
}
36+
37+
else
38+
{
39+
cmd.arguments(args);
40+
}
2541
}
2642
}
2743
}

AutoLoginBuilder/Worker.cs

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)