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
Solved

Need VB Code to set Registry Permissions

Posted on 2001-08-15
8
274 Views
Last Modified: 2013-01-23
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.
0
Comment
Question by:DesktopPro
8 Comments
 
LVL 38

Accepted Solution

by:
PaulHews earned 200 total points
ID: 6390257
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

Const LOGON32_LOGON_INTERACTIVE = 2
Const LOGON32_PROVIDER_DEFAULT = 0


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
 
 lngLogonType = LOGON32_LOGON_INTERACTIVE
 lngLogonProvider = LOGON32_PROVIDER_DEFAULT
 
 blnResult = RevertToSelf()
 
 blnResult = LogonUser(strAdminUser, strAdminDomain, strAdminPassword, lngLogonType, lngLogonProvider,
lngTokenHandle)
                                                     
 blnResult = ImpersonateLoggedOnUser(lngTokenHandle)
End Sub

Public Sub Logoff()
 Dim blnResult As Boolean
 
 blnResult = RevertToSelf()
End Sub
0
 
LVL 14

Expert Comment

by:wsh2
ID: 6390447
<ping>
0
 
LVL 6

Expert Comment

by:JonFish85
ID: 6390970
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...
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 3

Expert Comment

by:nzjonboy
ID: 6391058
listening...
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6391110
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)
0
 

Expert Comment

by:ratantata
ID: 6391147
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
**Cheers**
0
 

Author Comment

by:DesktopPro
ID: 6392697
Thanks, PaulHews.  I am going to try this as soon as I have a chance and will get back with you.
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 12766499
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
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

860 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