Writing Registry Values in Windows NT (Permissions issue?) 
Author Message
 Writing Registry Values in Windows NT (Permissions issue?)

I am currently working on a program that stores user preferences in
the registry.  

I have a class module that I downloaded from Planet Source Code and
have been quite successful in using it to Read/Write/Delete keys and
values in the Win95/98 registry.  However when I take the same
unmodified code and move it WinNT, I cannot write values to the
Registry.

I have no problems reading values in NT, but RegSetValueExA always
returns 5 when I attempt to write.  I believe a return code of 5
coresponds to a Permissions error, but I am running my program as
Administrator and have Full Permissions on the Key I am attempting to
write to.

Additonal information:
WinNT 4.0 sp4
Writing to HKLM\Software\MyCompany\MyProgrram
Working only with string values at this time.

Any info or insight would be greatly appriciated.

-Chris



Mon, 14 Jan 2002 03:00:00 GMT  
 Writing Registry Values in Windows NT (Permissions issue?)

Quote:

>I have no problems reading values in NT, but RegSetValueExA always
>returns 5 when I attempt to write.  I believe a return code of 5
>coresponds to a Permissions error, but I am running my program as
>Administrator and have Full Permissions on the Key I am attempting to
>write to.

Possibly a permissions issue, possibly not. Win95/98 will often work with
function declares that are "not quite right" while NT is not lenient at all. How
does your declare compare to this one:

Declare Function RegSetValueEx& Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal
hKey&, ByVal lpszValueName$, ByVal dwRes&, ByVal dwType&, ByVal lpDataBuff$,
ByVal nSize&)

That one is taken from my RegSetValue function, which definitely works in NT.
www.arcatapet.com/vbsource/regset.txt

Don Bradner
MSVB MVP

www.arcatapet.com



Tue, 15 Jan 2002 03:00:00 GMT  
 Writing Registry Values in Windows NT (Permissions issue?)
The Declare I have been using does match this one.  Regardless, I
tried to cut and paste the declare here, and got the same result.  I
also tried using the subprocedure located at the web address
specified.  Same result.

I have checked the permissions on the keys I am trying to write to.
Everything seems to be fine.  Any other ideas?  

You're help is very much appriciated.

-Chris



Quote:
>Possibly a permissions issue, possibly not. Win95/98 will often work with
>function declares that are "not quite right" while NT is not lenient at all. How
>does your declare compare to this one:

>Declare Function RegSetValueEx& Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal
>hKey&, ByVal lpszValueName$, ByVal dwRes&, ByVal dwType&, ByVal lpDataBuff$,
>ByVal nSize&)

>That one is taken from my RegSetValue function, which definitely works in NT.
>www.arcatapet.com/vbsource/regset.txt

>Don Bradner
>MSVB MVP

>www.arcatapet.com



Tue, 15 Jan 2002 03:00:00 GMT  
 Writing Registry Values in Windows NT (Permissions issue?)
I just cam across this myself. Error number 5 is indeed 'Permission denied'.
I can't speak to whether you should have any problems or not because you are
an administrator. But, I can say that permissions for the registry are set
in RegEdit32--not RegEdit. Look there for more insight to your permissions
problem.

Isaac Citrom



Tue, 15 Jan 2002 03:00:00 GMT  
 Writing Registry Values in Windows NT (Permissions issue?)
I have been using Regedt32 to check my permissions and ,to me,
everything looks okay.  Let me ask this:

If can go in and manually change the value  using RegEdt32,  doesn't
that mean that I have permission to change the value in code?  Is
there something that I might be missing?

Thanks again for your help. I appriciate your thoughts.

-Chris



Quote:
>I just cam across this myself. Error number 5 is indeed 'Permission denied'.
>I can't speak to whether you should have any problems or not because you are
>an administrator. But, I can say that permissions for the registry are set
>in RegEdit32--not RegEdit. Look there for more insight to your permissions
>problem.

>Isaac Citrom



Tue, 15 Jan 2002 03:00:00 GMT  
 Writing Registry Values in Windows NT (Permissions issue?)

Quote:

>The Declare I have been using does match this one.  Regardless, I
>tried to cut and paste the declare here, and got the same result.  I
>also tried using the subprocedure located at the web address
>specified.  Same result.

Hmm. I don't know what to tell you. I started a new project with a form and a
module. Pasted the text file I pointed you to into the module. Changed one line,
to make the HKLM constant public so that it would be usable in the form. Put a
command button on the form, with this code in its click event:

RegSetValue HKEY_LOCAL_MACHINE, "software\test\test1", "test2", "this is a test"

This was built on a Win98 machine and tested there, then made as an executable
across the local network to an NT4 Server. Run from there. A quick look with
RegEdit confirms that the key and value were created without problems.
Don Bradner
MSVB MVP

www.arcatapet.com



Wed, 16 Jan 2002 03:00:00 GMT  
 Writing Registry Values in Windows NT (Permissions issue?)
You are correct:

I followed the same steps you did, and the test program worked.  It
has got to be some obscure bug in the code I was using.  Thanks for
providing an example that proves the concept.  My sanity appriciates
it.

Regards,

-Chris



Quote:

>>The Declare I have been using does match this one.  Regardless, I
>>tried to cut and paste the declare here, and got the same result.  I
>>also tried using the subprocedure located at the web address
>>specified.  Same result.

>Hmm. I don't know what to tell you. I started a new project with a form and a
>module. Pasted the text file I pointed you to into the module. Changed one line,
>to make the HKLM constant public so that it would be usable in the form. Put a
>command button on the form, with this code in its click event:

>RegSetValue HKEY_LOCAL_MACHINE, "software\test\test1", "test2", "this is a test"

>This was built on a Win98 machine and tested there, then made as an executable
>across the local network to an NT4 Server. Run from there. A quick look with
>RegEdit confirms that the key and value were created without problems.
>Don Bradner
>MSVB MVP

>www.arcatapet.com



Fri, 18 Jan 2002 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Writing to registry on windows nt - 2000

2. In Windows NT how to write to registry?

3. writing to registry with Windows NT

4. An NT permissions issue

5. Windows 95 vs. Windows NT Registry updates

6. Registry WRITE/Change Permissions

7. Registry permissions on NT

8. writing vbscript to know the OS of a remote PC ( is WIndows NT or WIndows 2000)

9. VB5 Systray, Registry Issues and NT 4.0 - Pleaes Help

10. Changing Windows XP Registry permissions with VBScript.

11. Permissions required to write to the Windows Event Log

12. Permissions required to write to the Windows Event Log from VB5

 

 
Powered by phpBB® Forum Software