Can't write dword to registry correctly?

Posted on 2003-03-03
Medium Priority
Last Modified: 2008-01-16
I need to write a key to the registry with a value of 4294967295, which is what Windows Media services recognizes as 'no limit'.  The thing is I can write dWord values less than 2,147,483,647, but values any higher get automatically converted to a string registry entry.

Here is my code:
RegistryKey regKey = Registry.LocalMachine.CreateSubKey(@"SYSTEM\CurrentControlSet\Services\nsunicast\Parameters\Virtual Roots\/"+eId);
regKey.SetValue("MaxBandwidth", 4294967295); // if I change this to below the number above it will set as a dWord all day long.

Any examples, or ideas would be great.

Question by:begreening
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 22

Expert Comment

ID: 8060049
Alas, our fancy new c# is rather deficient in the formats values may be created with.

The only way around it is to call the various Reg* API routines directly, e.g.:

using Microsoft.Win32;
using System.Runtime.InteropServices;

namespace SysMonST

public class RegAPIWrapper
[DllImport("advapi32", EntryPoint="RegOpenKeyEx")]
public static extern int RegOpenKeyEx(uint hKey
                                      ,string lpSubKey
                                      ,int     ulOptions
                                      ,uint     samDesired
                                      ,IntPtr   phkResult);
[DllImport("advapi32", EntryPoint="RegCloseKey")]
public static extern bool RegCloseKey(int hKey);

[DllImport("advapi32", EntryPoint="RegQueryValueEx")]
public static extern bool RegQueryValueEx(IntPtr xkey
                                  ,string ValueName
                                  ,IntPtr  Reserved
                                  ,IntPtr  ValueType
                                  ,IntPtr  ValueBuf
                                  ,IntPtr  ValueBufSize);



int RegStatus;
IntPtr xkey;



Author Comment

ID: 8071991
Sorry but I can't seem to find enough information to make this code work.  Where do I find values for REG_FULL_ACCESS
 and HKLM?

Anyone know of a link to a tutorial or working example code?
LVL 22

Accepted Solution

cookre earned 600 total points
ID: 8072887
Sorry about that - those where constants defined elsewhere in the code I pulled the above snippet from:

uint         HKLM=0x80000002;
uint         REG_FULL_ACCESS=0x0002003F;
int          REG_SZ=1;

For definitions of the various constants used by the Reg* API routines, look in WINNT.H for KEY_ and REG_  (about 6800 lines down).

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question