Read from registry value

heman85

Registered User.
Local time
Today, 00:07
Joined
Jul 17, 2008
Messages
108
Hello People
I want to read from the registry a value. If the value = 1 the continue loading the main form. If th value dont exist or = 0 then close the database.

I think its a simple code but I cant find this code. Any Help on this?
Thanks
 
Look at GetSetting in VBA help, and see if it does what you want.
 
Wasn't there just an extensive discussion on this topic that you started a few days ago with a few answers complete with examples?

SHADOW
 
Wasn't there just an extensive discussion on this topic that you started a few days ago with a few answers complete with examples?

SHADOW
Yes but Any example have what I want.

Read my 1st post on this topic. I dontwant to write on the registry I want to read on registry and If the value = 1 thenload the form If not them close the DB

Al the example are for write. I dont want to write. I want to read and Load form.
 
Dim RegObj, RegKey
Set RegObj = CreateObject("WScript.Shell")
RegKey = RegObj.RegRead("HKCU\Software\Microsoft\Windows\Cu rrentVersion\Policies\System\DisableTaskMgr")
If RegKey = "" Then MsgBox "There is no registry value for this key!"
Else
MsgBox "Registry key value is " & RegKey & "!"
Set RegObj = Nothing
End If
End
========================
didn't you see this heman85? that is for reading. it states "REGREAD". I think you did not bothered studying it. or you can use the getsettings.

are you in difficulty analyzing it?

let me state it:

1. the first line of the code states that you are setting variable RegObj and RegKey

2. second line states that you are setting the value of RegObj to a created object thru wscript.shell

3. third line states that the value of RegKey is RegObj.RegRead.
RegRead means Read registry
the value of RegObj now that is specified here is "HKCU\Software \Microsoft\Windows\CurrentVersion\Policies\System\DisableTaskMgr" enclosed in parenthesis because this is your wscript.

This is the path of the registry key: "HKCU\Software \Microsoft\Windows\CurrentVersion\Policies\System\

This is the registry key: DisableTaskMgr (regardless what type of entry is this)

4. the fourth line states that if regkey is empty then you have that message

5. fifth line is ELSE part of coding
6. Sixth line states that if regkey has value that and message box will appear stating your regkey value.
7. seventh line states to clear memory
8. eight line state end of IF statement
9. ninth line states the end of that code.



Moreover, if that code has error, it is because the code did not see that registry "DisableTaskMgr". So you can add DIM regkey1

Regkey1=nz(regkey,"")
the above regkey1 states that if regkey is not found of empty then, empty)


Do you further questions?

I would like to reiterate to be careful messing around the registry not to delete other key other than you created.
 
Ok I got it...

Private Sub Form_Open(Cancel As Integer)
Dim RegObj, RegKey
Set RegObj = CreateObject("WScript.Shell")
RegKey = RegObj.RegRead("HKLM\Software\My application\Security Code")
If RegKey = 0 Then DoCmd.Quit
End Sub

But Now I receive a Debug Windowif the registry key are not allowed.

How can I hide this debug window???
 
OK my final
Form_Open(Cancel As Integer)
Dim RegObj, RegKey
Set RegObj = CreateObject("WScript.Shell")
RegKey = RegObj.RegRead("HKLM\Software\My aplication\Security Code")
If Not RegKey = 1 Then DoCmd.Quit
End Sub
 
your code is nearly there....

my question is does HKLM\software\my application\security code do exist in your registry?

what type of registry did you use? REG_dword or Reg_SZ?

what does the debug windows says?
 
your code is nearly there....

my question is does HKLM\software\my application\security code do exist in your registry?

what type of registry did you use? REG_dword or Reg_SZ?

what does the debug windows says?

Its ok Marianne
WIth the if not = 1 no windows appear.

Marriane THANKS VERY MUCH for all your help on this post.
Thanks for taking from your time :)
 
dont thank me yet. see if your code do really perform what you want to achieve.

again, BE CAREFUL PLAYING AROUND THE REGISTRY.
 
your code is nearly there....

my question is does HKLM\software\my application\security code do exist in your registry?

what type of registry did you use? REG_dword or Reg_SZ?

what does the debug windows says?
Reg_dWORD

and yes Its doing what I want
If the registry key do not exist or its not = 1 close the db
 

Users who are viewing this thread

Back
Top Bottom