Microsoft.Win32 命名空间中 RegistryKey 类包含称为 SetValue 方法。 此方法用于系统注册表中存储值。 SetValue 方法中第一个参数是字符串, 指定值的名称。 第二个参数是包含要存储数据对象。 对象类型决定将用来存储值注册表类型。
如果 SetValue 中第二个参数为 Int 32 值, 按整数用 REG _ DWORD 注册表值类型是存储值。 作为与 REG _ SZ 注册表值类型字符串但是, 如果第二个参数是任何 其他 类型的整数 (如 Int 16、 UInt 16、 UInt 32 和等等), 是存储值。
解决方案
<script type="text/javascript">loadTOCNode(1, 'resolution');</script>
将 Int32 非整数值存储在注册表作为 REG _ DWORD 值, typecast Int32 非整数值为 Int 32 值。
使用 VisualC # 代码以下示例将 UInt 32 值存储在注册表作为 REG _ DWORD 值:
using System;
using Microsoft.Win32;
namespace MyNamespace {
class MyClass {
static void Main() {
UInt32 Val = UInt32.MaxValue;
RegistryKey MyKey =
Registry.CurrentUser.CreateSubKey("SOFTWARE//MyApp");
MyKey.SetValue("MyVal_String", Val); // store as REG_SZ
MyKey.SetValue("MyVal_DWORD", (Int32) Val); // store as REG_DWORD
}
}
}
对于 VisualC++ 使用以下示例代码:
#using <mscorlib.dll>
using namespace System;
using namespace Microsoft::Win32;
int main(void) {
UInt32 Val = UInt32::MaxValue;
RegistryKey *MyKey =
Registry::CurrentUser->CreateSubKey("SOFTWARE//MyApp");
MyKey->SetValue(S"MyVal_String", __box(Val)); // store as REG_SZ
MyKey->SetValue(S"MyVal_DWORD", __box((Int32) Val)); // store as REG_DWORD
return 0;
}