|
Компьютерный форум OSzone.net » Программирование, базы данных и автоматизация действий » Программирование и базы данных » C/C++ - помощь с с# |
|
C/C++ - помощь с с#
|
Пользователь Сообщения: 87 |
Профиль | Отправить PM | Цитировать
Я начинающий пишу программу на экзамен для удаления программ. Надо добавить кнопку типа злое удалени, когда инсталятор программы написан криво, а удалить ее надо. Она будет удалять ключ с реестра и папку установки. Обьясните и поиогите это осуществить. Заранее СПАСИБО
|
|
Отправлено: 11:16, 27-05-2013 |
Ветеран Сообщения: 1404
|
Профиль | Отправить PM | Цитировать Если я не ошибаюсь, то в windows 7 информация об инсталлированных хранится в разделе реестра HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\
На других компьютерах вид ключа будет другим. Считывание из реестра на WinAPI производится функциями: RegCreateKey , RegCreateKeyEx В C# для этого создан класс RegistryKey Пример использования класса в MSDN ( взять документацию можно в Windows SDK ) using System; using System.Security.Permissions; using Microsoft.Win32; [assembly: RegistryPermissionAttribute(SecurityAction.RequestMinimum, ViewAndModify = "HKEY_CURRENT_USER")] class RegKey { static void Main() { // Create a subkey named Test9999 under HKEY_CURRENT_USER. RegistryKey test9999 = Registry.CurrentUser.CreateSubKey("Test9999"); // Create two subkeys under HKEY_CURRENT_USER\Test9999. The // keys are disposed when execution exits the using statement. using(RegistryKey testName = test9999.CreateSubKey("TestName"), testSettings = test9999.CreateSubKey("TestSettings")) { // Create data for the TestSettings subkey. testSettings.SetValue("Language", "French"); testSettings.SetValue("Level", "Intermediate"); testSettings.SetValue("ID", 123); } // Print the information from the Test9999 subkey. Console.WriteLine("There are {0} subkeys under {1}.", test9999.SubKeyCount.ToString(), test9999.Name); foreach(string subKeyName in test9999.GetSubKeyNames()) { using(RegistryKey tempKey = test9999.OpenSubKey(subKeyName)) { Console.WriteLine("\nThere are {0} values for {1}.", tempKey.ValueCount.ToString(), tempKey.Name); foreach(string valueName in tempKey.GetValueNames()) { Console.WriteLine("{0,-8}: {1}", valueName, tempKey.GetValue(valueName).ToString()); } } } using(RegistryKey testSettings = test9999.OpenSubKey("TestSettings", true)) { // Delete the ID value. testSettings.DeleteValue("id"); // Verify the deletion. Console.WriteLine((string)testSettings.GetValue( "id", "ID not found.")); } // Delete or close the new subkey. Console.Write("\nDelete newly created registry key? (Y/N) "); if(Char.ToUpper(Convert.ToChar(Console.Read())) == 'Y') { Registry.CurrentUser.DeleteSubKeyTree("Test9999"); Console.WriteLine("\nRegistry key {0} deleted.", test9999.Name); } else { Console.WriteLine("\nRegistry key {0} closed.", test9999.ToString()); test9999.Close(); } } } |
------- Отправлено: 14:37, 28-05-2013 | #2 |
Для отключения данного рекламного блока вам необходимо зарегистрироваться или войти с учетной записью социальной сети. Если же вы забыли свой пароль на форуме, то воспользуйтесь данной ссылкой для восстановления пароля. |
Пользователь Сообщения: 87
|
Профиль | Отправить PM | Цитировать |
Отправлено: 16:26, 28-05-2013 | #3 |
Ветеран Сообщения: 1404
|
Профиль | Отправить PM | Цитировать Цитата asacyra:
Пример из MSDN: using System; using System.IO; class Test { public static void Main() { // Specify the directories you want to manipulate. string path = @"c:\MyDir"; string target = @"c:\TestDir"; try { // Determine whether the directory exists. if (!Directory.Exists(path)) { // Create the directory it does not exist. Directory.CreateDirectory(path); } if (Directory.Exists(target)) { // Delete the target to ensure it is not there. Directory.Delete(target, true); } // Move the directory. Directory.Move(path, target); // Create a file in the directory. File.CreateText(target + @"\myfile.txt"); // Count the files in the target directory. Console.WriteLine("The number of files in {0} is {1}", target, Directory.GetFiles(target).Length); } catch (Exception e) { Console.WriteLine("The process failed: {0}", e.ToString()); } finally {} } } |
|
------- Отправлено: 16:36, 28-05-2013 | #4 |
Участник сейчас на форуме | Участник вне форума | Автор темы | Сообщение прикреплено |
| |||||
Название темы | Автор | Информация о форуме | Ответов | Последнее сообщение | |
Вопрос - помощь | корвин | Ноутбуки | 0 | 12-03-2013 14:44 | |
помощь | сергей лт | Тест-форум | 2 | 17-03-2011 18:34 | |
Debian/Ubuntu - Помощь. | suntaxis | Общий по Linux | 1 | 30-01-2011 16:43 |
|