Need VB Code to set Registry Permissions

I am in need of VB code to change the permissions on a specific key in the registry.  Does anyone know if this is possible?  Here are the details:  I am writing .msi files and VB scripts to completely Automate configuration of Windows 2000 Professional (soon to be XP so it should work for both).  I created a value in the registry under HKLM\System\CurrCtlSet\LanManServer\Parameters named SrvComment that uses variables to show the currently logged on user under the Server Comment.  All works fine except that when a standard user logs on, they do not have sufficient permission to modify this registry key.  If I manually change this permission it will work, but I want to automate everything.  So I need to find a way to automatically change the permission to this registry key so I don't have to touch it.  Lack of security on this key does not concern me.
Who is Participating?
PaulHewsConnect With a Mentor Commented:
Never tried this in 2000, but it works in NT.

You could try impersonation code when you access the key.  Call Logon to make the code behave in the security context of the user you specify.  Call logoff again to reset security context of the running code.

Declare Function RevertToSelf Lib "advapi32.dll" () As Long

Declare Function LogonUser Lib "advapi32.dll" Alias "LogonUserA" (ByVal lpszUsername As String, ByVal
lpszDomain As String, ByVal lpszPassword As String, ByVal dwLogonType As Long, ByVal dwLogonProvider
As Long, phToken As Long) As Long

Declare Function ImpersonateLoggedOnUser Lib "advapi32.dll" (ByVal hToken As Long) As Long


Public Sub Logon(ByVal strAdminUser As String, ByVal strAdminPassword As String, ByVal strAdminDomain
As String)
 Dim lngTokenHandle, lngLogonType, lngLogonProvider As Long
 Dim blnResult As Boolean
 lngLogonProvider = LOGON32_PROVIDER_DEFAULT
 blnResult = RevertToSelf()
 blnResult = LogonUser(strAdminUser, strAdminDomain, strAdminPassword, lngLogonType, lngLogonProvider,
 blnResult = ImpersonateLoggedOnUser(lngTokenHandle)
End Sub

Public Sub Logoff()
 Dim blnResult As Boolean
 blnResult = RevertToSelf()
End Sub
wow nice code PaulHews! Where'd you find that? or did you cram it together yourself? Keepin an eye on this one, as I may find use for the code sometime...
7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.

That's from MSKB.  Originally used it in ASP applications to access data on the network (ASP app running under limited inet user security and couldn't access any network files)
Suggestion- how about making the config application run as a service that monitors all users?
Since NT services starts even before any user logs on, this might be useful
DesktopProAuthor Commented:
Thanks, PaulHews.  I am going to try this as soon as I have a chance and will get back with you.
do you have the Database setup?

The last thing is you have to Put it on your phone (usually a Jar file)

a)wap or a sync cable are your options or if your phone Supports MMS you can email it as a attachment
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.

All Courses

From novice to tech pro — start learning today.