Example #1
0
    //  Write a System.int to the registry.
    public bool SetValue(string strKeyName, string strValueName, int intValue)
    {
        //  Open HKEY_LOCAL_MACHINE\SOFTWARE\YaoDurant\...
        intReturn =
            WinRegCE.RegCreateKeyEx(hkeyHive,
                                    strYDKey + @"\" + strKeyName,
                                    0, string.Empty, 0, 0,
                                    IntPtr.Zero,
                                    ref hkeyCurrent,
                                    ref regdispResult);
        if (intReturn != 0)
        {
            return(false);
        }

        //  Store intValue under the name strValueName. for
        //  platform independence, use Marshal.SizeOf(intValue),
        //     not "4", to specify the size in bytes of a
        //     System.int.
        intReturn =
            WinRegCE.RegSetValueEx(hkeyCurrent,
                                   strValueName,
                                   0, 0,
                                   ref intValue,
                                   Marshal.SizeOf(intValue));
        if (intReturn != 0)
        {
            return(false);
        }

        //  Close the key.
        intReturn = WinRegCE.RegCloseKey(hkeyCurrent);
        if (intReturn != 0)
        {
            return(false);
        }

        return(true);
    }
Example #2
0
    //  Write a System.string  to the registry.
    public bool SetValue(string strKeyName,
                         string strValueName,
                         string strValue)
    {
        //  Open HKEY_LOCAL_MACHINE\SOFTWARE\YaoDurant\...
        intReturn =
            WinRegCE.RegCreateKeyEx(hkeyHive,
                                    strYDKey + @"\" + strKeyName,
                                    0, string.Empty, 0, 0,
                                    IntPtr.Zero,
                                    ref hkeyCurrent,
                                    ref regdispResult);
        if (intReturn != 0)
        {
            return(false);
        }

        //  Store strValue under the name strValueName.
        intReturn =
            WinRegCE.RegSetValueEx(hkeyCurrent, strValueName,
                                   0, WinRegCE.REGTYPE.REG_SZ,
                                   strValue,
                                   strValue.Length * 2 + 1);
        if (intReturn != 0)
        {
            return(false);
        }

        //  Close the key.
        intReturn = WinRegCE.RegCloseKey(hkeyCurrent);
        if (intReturn != 0)
        {
            return(false);
        }

        return(true);
    }