Link to home
Start Free TrialLog in
Avatar of bill_sutton
bill_suttonFlag for United States of America

asked on

Allowing non-administrators to write to HKLM\software\myapp on XP with VB6

Hi-

I see that this exact question has been asked before but if there was a solution, it was not evident to me. And even though it appears from looking at similar questions that there is not solution to my problem, I shall ask it again anyway:

I have a VB6 application running on XP which stores user selectable options in the HKLM\software\myApp registry key. These options are really application specific rather than user specific which is why I really need to store the information there (I need to avoid using the HKCU key). My problem is that in order to write to my registry key, the user has to have administrative privileges which most users do not. My current work around is to go to each PC and using REGEDT32 with the administrator account, give the everyone group full control of the HKLM\Software\MyApp registry key. This is not a practical workaround. Is there a way using VB that I can grant the everyone group full control of the myapp registry key when I create it? I’m a hardware guy not a software guy, so don’t get too complex with responses.

Thanks for your help,
Bill
Avatar of sirbounty
sirbounty
Flag of United States of America image

Hmm - there may be a 'better' solution, so feel free to wait on further input, but I've found one workaround - schedule the import via a shelled command, which uses the system account...

Here's somewhat what I'm referring to...

'Get the 'new time' - 15 minutes from now...

InstallTime=format(DateAdd("n",15,time),"HH:mm:ss")

Next, run a shelled import using the above time:

Shell "schtasks /create /ru system /sc once /st " & NewTime & " /tn RegImport /tr " & chr(34) & "reg add HKLM\Software\MyApp /v MyValue /d MyData" & chr(34)

Now, this should launch a scheduled task using the Local System account to run the reg import, 15 minutes from the current time...
I may have misread the situation, but why don't you use SaveSetting/GetSetting which is designed for that scenario.
Avatar of soco180
soco180

Here is a hack suggestion that shouldn't require you to change any code.

How about create a batch file to do exactly what you are doing manually. Place that batch file in a public share. Then add a line of code to your VB app to execute the batch file on start up...

'****************************************
'Insert this into a bas module
'****************************************
Public Const SW_SHOW As Long = 5
Public Const SW_SHOWNORMAL As Long = 1
Public Const SW_SHOWMAXIMIZED As Long = 3
Public Const SW_SHOWDEFAULT As Long = 10

Public Declare Function ShellExecute Lib "shell32" _
   Alias "ShellExecuteA" _
  (ByVal hWnd As Long, _
   ByVal lpOperation As String, _
   ByVal lpFile As String, _
   ByVal lpParameters As String, _
   ByVal lpDirectory As String, _
   ByVal nShowCmd As Long) As Long

Public Declare Function GetDesktopWindow Lib "user32" () As Long

Public Sub RunShellExecute(sTopic As String, sFile As Variant, _
                            sParams As Variant, sDirectory As Variant, _
                            nShowCmd As Long)

  'execute the passed operation, passing
  'the desktop as the window to receive
  'any error messages
   Call ShellExecute(GetDesktopWindow(), _
                     sTopic, _
                     sFile, _
                     sParams, _
                     sDirectory, _
                     nShowCmd)

End Sub



'****************************************
'Then add this line of code somewhere in
'your app either in an error handler, or
'in the project startup object
'(probably overkill but you shouldn't
'have to change any existing code)
'****************************************
RunShellExecute "open", "\\Server\PublicShare\MyBatchFile.bat", 0&, 0&, SW_SHOWNORMAL
Avatar of bill_sutton

ASKER

Thanks for the quick replies... I have a situation that prevents me from looking closly at these today but on quick glance: I like the Get/Save settings idea execpt that they are for the current user and not for the Application.
The scheduling idea might work except that the optins need to be stored in real time (users make changes, save,  then execute a test. If another user comes by later, they need to pick up with the last settings).
It is not immediatly clear to me what the last idea does or if it will help me, I will look closer at it tomorrow.
Thanks again,
Bill
ASKER CERTIFIED SOLUTION
Avatar of soco180
soco180

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think that the third solution may be the one that I am looking for; I implemented it and tried it on a couple of machines... while I still need admin priveledge to create the key in the first place (at least on one machine) after that it seems that everyone can update it. Lets see what happens when I release it to the general public.

I'll get back by Tuesday.

Thanks!
Bill
Bill, I am glad to here that.

FYI...REGINI will actually create the key if it does not exist.
For instance, had you actually ran the \Registry\Machine\SOFTWARE\AppTest [1 5 7] without changing it, REGINI would have created a new Key HKLM\SOFTWARE\AppTest.

So you may be able to rely on REGINI to even create the key.

Now I am not 100% sure about that because when I tested it I was the local ADMIN on my PC.

However, another approach, what if you used REGINI to give the Everyone account FullControl on the HKLM\SOFTWARE key before creating your new reg entry?