Здравствуйте!
Опишу вкратце свои действия: 1) добавляю reg-ский файл в реестр след образом
| Код | //Для Windows 7 ProcessStartInfo startInfo = new ProcessStartInfo((Environment.GetEnvironmentVariable("windir")) + "\\regedit.exe", "/s " + fname + ""); Process np = new Process(); startInfo.Verb = "runas"; np.StartInfo = startInfo; np.Start();
|
А так если ОС Win XP
| Код | //Для Win XP Process proc = new Process(); try { proc.StartInfo.FileName = "regedit.exe"; proc.StartInfo.UseShellExecute = false; proc = Process.Start((Environment.GetEnvironmentVariable("windir")) + "\\regedit.exe", "/s " + fname + ""); if (proc != null) proc.WaitForExit(); }
finally { if (proc != null) proc.Dispose(); }
|
2) Проверяю добавилась ли ветка
Вроде бы все хорошо в реестр все прописывается (в regedit), но когда я проверяю (см код ниже) программа не видит эту ветку (проблема только в Win7, на XP все работает отлично).
| Код | private void Verif(string _userId) { //----------Перевожу имя импортируемого контейнера byte[] inp_bytes = Encoding.Default.GetBytes(fcontName); string currContName = null; List<string> listContByte = new List<string>();
foreach (int curbyte in inp_bytes) { currContName += curbyte.ToString(); }
//----------Перевожу имена уже установленных контейнеров RegistryKey rk = null; //-------- if (IntPtr.Size == 8) { rk = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Wow6432Node\\Crypto Pro\\Settings\\USERS\\" + _userId + "\\Keys\\",true); } else { rk = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Crypto Pro\\Settings\\USERS\\" + _userId + "\\Keys\\",true); } //--------
foreach (string st in rk.GetSubKeyNames()) { string allContName = null; using (RegistryKey tempKey = rk.OpenSubKey(st,true)) {
foreach (string valName in tempKey.GetValueNames()) {
if (valName == "name.key") { byte[] bytes = (byte[])tempKey.GetValue(valName); for (int curByte = 4; curByte < bytes.Length; curByte++) { allContName += bytes[curByte].ToString(); } listContByte.Add(allContName); } } } } int count = 0; foreach (string str in listContByte) { if (Equals(str, currContName)) count++; }
if (count != 0) MessageBox.Show("Контейенер " + fcontName.ToString() + " успешно импортирован!", "Успех"); else MessageBox.Show("Не удалось импортировать!", "Отказ"); }
|
Подскажите в какой части допустил ошибку! |