1414using System . Windows . Navigation ;
1515using System . Windows . Shapes ;
1616using Microsoft . Win32 ;
17+ using System . Security . AccessControl ;
1718
1819namespace Configurator
1920{
@@ -26,18 +27,38 @@ public partial class MainWindow : Window
2627 ObservableCollection < ConfigModel > context ;
2728 static string credential_provider_guid = "ad471e7d-5bb2-4863-b317-faf3ad0f4d9d" ; //identifies credential provider to system
2829 static string credential_key = "HKEY_LOCAL_MACHINE\\ SOFTWARE\\ Microsoft\\ Windows\\ CurrentVersion\\ Authentication\\ Credential Providers\\ " ;
30+ static string credential_key_s = "HKEY_LOCAL_MACHINE\\ SOFTWARE\\ Microsoft\\ Windows\\ CurrentVersion\\ Authentication\\ Credential Providers" ;
2931 static string cp_name = "BootShellCredentialProvider" ;
3032 static string class_root_key = "HKEY_CLASSES_ROOT\\ CLSID\\ {" + credential_provider_guid + "}" ;
31-
32-
33+ static string userInitSetting = "C:\\ Windows\\ System32\\ Userinit.exe,ConfigurableShell.exe" ;
34+ static string userInitSetting_reset = "C:\\ Windows\\ System32\\ Userinit.exe," ;
35+ static string winlogonKey = "SOFTWARE\\ Microsoft\\ Windows NT\\ CurrentVersion\\ WinLogon" ;
36+ static string winlogonKey_full = "HKEY_LOCAL_MACHINE\\ SOFTWARE\\ Microsoft\\ Windows NT\\ CurrentVersion\\ WinLogon" ;
37+ public static string app_key_base_light = "SOFTWARE\\ Castle\\ BootShellCredentialProvider\\ Shells" ;
3338 public MainWindow ( )
3439 {
3540 context = new ObservableCollection < ConfigModel > ( ) ;
36-
37- context . Add ( new ConfigModel ( "Unity" , "-c \" cd ~/ && ./unity.sh\" " , "bash.exe" ) ) ;
38- context . Add ( new ConfigModel ( "XFCE" , "-c \" cd ~/ && ./xfce.sh\" " , "bash.exe" ) ) ;
39- context . Add ( new ConfigModel ( "Cinnamon" , "-c \" cd ~/ && ./cinnamon.sh\" " , "bash.exe" ) ) ;
40- context . Add ( new ConfigModel ( "Windows Explorer" , "/C \" explorer.exe\" " , "cmd.exe" , false ) ) ;
41+ var hkcl = Microsoft . Win32 . Registry . LocalMachine ;
42+ try
43+ {
44+ //load settings if present
45+ var subkey = hkcl . OpenSubKey ( app_key_base_light , true ) ;
46+ var subkeys = subkey . GetSubKeyNames ( ) ;
47+ foreach ( var k in subkeys )
48+ {
49+ context . Add ( new ConfigModel ( k , "x" , "y" ) ) ;
50+ }
51+ } catch ( ArgumentException )
52+ {
53+ //create defaults otherwise
54+ context . Add ( new ConfigModel ( "Unity" , "-c \" cd ~/ && ./unity.sh\" " , "bash.exe" ) ) ;
55+ context . Add ( new ConfigModel ( "XFCE" , "-c \" cd ~/ && ./xfce.sh\" " , "bash.exe" ) ) ;
56+ context . Add ( new ConfigModel ( "Cinnamon" , "-c \" cd ~/ && ./cinnamon.sh\" " , "bash.exe" ) ) ;
57+ context . Add ( new ConfigModel ( "Mate" , "-c \" cd ~/ && ./mate.sh\" " , "bash.exe" ) ) ;
58+ context . Add ( new ConfigModel ( "Windows Explorer" , "/C \" explorer.exe\" " , "cmd.exe" , false ) ) ;
59+ }
60+
61+
4162
4263 InitializeComponent ( ) ;
4364 lstView . ItemsSource = context ;
@@ -59,6 +80,25 @@ private void Save_button_click(object sender, RoutedEventArgs e)
5980 Registry . SetValue ( class_root_key , "" , cp_name ) ;
6081 Registry . SetValue ( class_root_key + "\\ InprocServer32" , "ThreadingModel" , "Apartment" ) ;
6182 Registry . SetValue ( class_root_key + "\\ InprocServer32" , "" , cp_name + ".dll" ) ;
83+ //Take ownership of WinLogon Key & update userinit
84+ try
85+ {
86+ string user = Environment . UserDomainName + "\\ " + Environment . UserName ;
87+ var hklm = Microsoft . Win32 . Registry . LocalMachine ;
88+ var rs = new RegistrySecurity ( ) ;
89+ rs . AddAccessRule ( new RegistryAccessRule ( user ,
90+ RegistryRights . FullControl ,
91+ InheritanceFlags . None ,
92+ PropagationFlags . None ,
93+ AccessControlType . Allow ) ) ;
94+
95+ var subkey = hklm . OpenSubKey ( winlogonKey , true ) ;
96+ subkey . SetAccessControl ( rs ) ;
97+ //update UserInit setting
98+
99+ Registry . SetValue ( winlogonKey_full , "Userinit" , userInitSetting ) ;
100+ }
101+ catch ( UnauthorizedAccessException ) { return ; } ;
62102 }
63103
64104 private void Reset_button_Click ( object sender , RoutedEventArgs e )
@@ -103,7 +143,7 @@ private void Disable_button_Click(object sender, RoutedEventArgs e)
103143 var hklm = Microsoft . Win32 . Registry . LocalMachine ;
104144 try
105145 {
106- var subkey = hklm . OpenSubKey ( "SOFTWARE \\ Microsoft \\ Windows \\ CurrentVersion \\ Authentication \\ Credential Providers" , true ) ;
146+ var subkey = hklm . OpenSubKey ( credential_key_s , true ) ;
107147 subkey . DeleteSubKey ( "{" + credential_provider_guid + "}" ) ;
108148 }
109149 catch ( ArgumentException ) { }
@@ -115,6 +155,12 @@ private void Disable_button_Click(object sender, RoutedEventArgs e)
115155 var parent_key = hkcl . OpenSubKey ( "CLSID" , true ) ;
116156 parent_key . DeleteSubKey ( "{" + credential_provider_guid + "}" ) ;
117157 } catch ( ArgumentException ) { }
158+
159+ //unregister configurableShell
160+ try
161+ {
162+ Registry . SetValue ( winlogonKey_full , "Userinit" , userInitSetting_reset ) ;
163+ } catch ( ArgumentException ) { }
118164 }
119165
120166 private void New_Button_Click ( object sender , RoutedEventArgs e )
0 commit comments