Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Loops Section Overview
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

580 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