C# проблема с реестром

Discussion in 'С/С++, C#, Rust, Swift, Go, Java, Perl, Ruby' started by noxjoker, 6 Dec 2009.

  1. noxjoker

    noxjoker Member

    Joined:
    7 Aug 2009
    Messages:
    189
    Likes Received:
    24
    Reputations:
    0
    Здраствуйте у меня есть проблема не могу решить её средствами C#.

    Code:
    Microsoft.Win32.RegistryKey Sp3 = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", true);  
    Sp3.SetValue("SFCSetting", 0xffffff9d, Microsoft.Win32.RegistryValueKind.DWord);    // Возникает ерор    The type of the value object did not match the specified RegistryValueKind or the object could not be properly converted.         
    Sp3.Close();
    Кто поможет или рациональное решение (без создание батников там или ищо чото) тому +
     
    #1 noxjoker, 6 Dec 2009
    Last edited: 6 Dec 2009
  2. noxjoker

    noxjoker Member

    Joined:
    7 Aug 2009
    Messages:
    189
    Likes Received:
    24
    Reputations:
    0
    xlinux между твоим и мои кодом нет разницы! Та же ошыбка ((( также хочу пояснить что оно должно создать REG_DWORD а не REG_SZ.

    Просто положите мне этот код в C#

    Code:
    Windows Registry Editor Version 5.00
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon]
    "SFCSetting"=dword:ffffff9d
    Люди Help :confused: :confused:
     
  3. noxjoker

    noxjoker Member

    Joined:
    7 Aug 2009
    Messages:
    189
    Likes Received:
    24
    Reputations:
    0
    SitraIT мне бы просто код.

    Вот Погуглил хотел бы спросить может кто знает как работать с advapi32.dll в C#
    Желательно Пример как записать в реестр .

    Зарание спасибо....
     
  4. BrainDeaD

    BrainDeaD Elder - Старейшина

    Joined:
    9 Jun 2005
    Messages:
    774
    Likes Received:
    292
    Reputations:
    214
    Code:
    [StructLayout(LayoutKind.Sequential)]
            public struct SECURITY_ATTRIBUTES
            {
                public int nLength;
                public IntPtr lpSecurityDescriptor;
                public bool bInheritHandle;
            }
    [DllImport("advapi32.dll", EntryPoint = "RegCreateKeyEx")]
              public static extern uint RegCreateKeyEx(uint hKey, string lpSubKey, uint Reserved, string lpClass, uint dwOptions, uint samDesired, ref SECURITY_ATTRIBUTES lpSecurityAttributes, ref uint phkResult, ref uint lpdwDisposition);
              [DllImport("advapi32.dll", EntryPoint = "RegSetValueEx")]
              public static extern uint RegSetValueEx(uint hKey, string lpValueName, uint Reserved, uint dwType, string lpData, uint cbData);
    static void SetKey()
            {
                SECURITY_ATTRIBUTES secattr = new SECURITY_ATTRIBUTES();
                secattr.nLength = Marshal.SizeOf(secattr);
                secattr.lpSecurityDescriptor = (IntPtr)0;
                secattr.bInheritHandle = true;
    
                uint neworused = 0;
                uint hIDKey = 0;
    
                RegistryKey key = Registry.LocalMachine;
                RegistryKey currKey = key.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon");
    
                uint res = RegCreateKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon", 0, null, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, ref secattr, ref hIDKey, ref neworused);
                if (res == ERROR_SUCCESS)
                {
                    res = RegSetValueEx(hIDKey, "SFCSetting", 0, REG_SZ, "dword:ffffff9d", keyLength);
                }
    что-то вроде этого. разбирайтесь. к сожалению сейчас нет времени помочь большим.
     
    1 person likes this.
  5. Algol

    Algol New Member

    Joined:
    29 May 2002
    Messages:
    1,759
    Likes Received:
    4
    Reputations:
    0
    Sp3.SetValue("SFCSetting", (int)0xffffff9d, Microsoft.Win32.RegistryValueKind.DWord);
     
  6. noxjoker

    noxjoker Member

    Joined:
    7 Aug 2009
    Messages:
    189
    Likes Received:
    24
    Reputations:
    0
    Algol Не работает... Ищу ответ ...
     
  7. DeaD_MoroZ

    DeaD_MoroZ Banned

    Joined:
    3 Nov 2009
    Messages:
    102
    Likes Received:
    7
    Reputations:
    0
    LONG RegCreateKeyEx (
    HKEY hKey, // дескриптор открытого ключа
    LPCTSTR lpSubKey, // адрес имени подключа
    DWORD Reserved, // зарезервировано
    LPTSTR lpClass, // адрес строки класса
    DWORD dwOptions, // флаг особых опций
    REGSAM samDesired, // желаемый доступ безопасности
    LPSECURITY_ATTRIBUTES lpSecurityAttributes, // адрес структуры ключа безопасности
    PHKEY phkResult, // адрес буфера для открытого ключа
    LPDWORD lpdwDisposition // адрес буфера характерного значения
    );
     
  8. noxjoker

    noxjoker Member

    Joined:
    7 Aug 2009
    Messages:
    189
    Likes Received:
    24
    Reputations:
    0
    DeaD_MoroZ ищу ответ на C# а не на C++ ...
     
  9. Algol

    Algol New Member

    Joined:
    29 May 2002
    Messages:
    1,759
    Likes Received:
    4
    Reputations:
    0
    Какой ответ?
    Вопрос-то про что ?
    Про ошибку "The type of the value object did not match the specified RegistryValueKind or the object could not be properly converted." ?
    Тогда ответ см в сообщении #6.
    Если про что-то другое - сформулируй нормально вопрос.
    ("Не работает" это не формулировка проблемы)
     
  10. noxjoker

    noxjoker Member

    Joined:
    7 Aug 2009
    Messages:
    189
    Likes Received:
    24
    Reputations:
    0
    Algol ты пробывал компилировать то что ты написал ???
    ТА ЖЕ ОШЫБКА !!!

    А ВОПРОС ТАКОВ:
    Как записать в SFCSetting параметр ffffff9d?
     
  11. Algol

    Algol New Member

    Joined:
    29 May 2002
    Messages:
    1,759
    Likes Received:
    4
    Reputations:
    0
    Да, я обычно компилирую код :)

    [​IMG]
     
  12. noxjoker

    noxjoker Member

    Joined:
    7 Aug 2009
    Messages:
    189
    Likes Received:
    24
    Reputations:
    0
    Algol СПС все работает ... +