Can't write dword to registry correctly?

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.

Thanks,
Bill
LVL 1
begreeningAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cookreCommented:
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;

xkey=(IntPtr)0;
RegStatus=RegAPIWrapper.RegOpenKeyEx(HKLM
 ,"System\\...snip...200a-4a2d-9e87-d30b0be79f1e}"
 ,0
 ,REG_FULL_ACCESS
 ,xkey);  

etc...
0
begreeningAuthor Commented:
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?
0
cookreCommented:
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).
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.