Exemplo n.º 1
0
        private void SetReg(string username, string value)
        {
            string      loadedHiveKey = RegistryInterop.Load(@"c:\users\" + username + @"\ntuser.dat");
            RegistryKey rk            = Registry.Users.OpenSubKey(loadedHiveKey, true);

            if (rk != null)
            {
                RegistryKey ExistKey = rk.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion\Winlogon", true);
                ExistKey.SetValue(@"Shell", value, RegistryValueKind.String);
                ExistKey.Close();
                rk.Close();
            }
            RegistryInterop.Unload();
        }
Exemplo n.º 2
0
        private string getReg(string username)
        {
            string result = "";
            int    flag   = 0;

            string user_path     = @"C:\Users\";
            string subkey_exists = "Shell";

            //if (Directory.Exists(user_path))
            {
                //string[] sub_dirs = Directory.GetDirectories(user_path);

                //foreach (string dir in sub_dirs)
                {
                    string wimHivePath = @"c:\users\" + username + @"\ntuser.dat";
                    //MessageBox.Show(wimHivePath);
                    string loadedHiveKey = RegistryInterop.Load(wimHivePath);

                    RegistryKey rk = Registry.Users.OpenSubKey(loadedHiveKey);

                    if (rk != null)
                    {
                        RegistryKey ExistKey = rk.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion\Winlogon", RegistryKeyPermissionCheck.ReadWriteSubTree);

                        if (ExistKey != null)
                        {
                            if (ExistKey.GetValue("shell").ToString() != null)
                            {
                                result = ExistKey.GetValue("shell").ToString();
                            }
                        }

                        ExistKey.Close();


                        rk.Close();
                    }

                    RegistryInterop.Unload();
                }
            }

            return(result);
        }