Results 1 to 9 of 9

Thread: kedaman......another question

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    India
    Posts
    298

    kedaman...............

    kedaman,

    how do I use ur code to read:

    HKEY_CURRENT_USER\Control Panel\desktop\ScreenSaveActive"

    I used regval(HKEY_CURRENT_USER\Control Panel\desktop\ScreenSaveActive" )

    but was unable to retrieve the value.Thanx.




    [Edited by rammy on 09-18-2000 at 08:24 AM]

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    You can something like this:
    Code:
    Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
    
    Private Const KEY_QUERY_VALUE = &H1
    Private Const KEY_SET_VALUE = &H2
    Private Const KEY_ENUMERATE_SUB_KEYS = &H8
    Private Const KEY_NOTIFY = &H10
    Private Const KEY_CREATE_LINK = &H20
    Private Const KEY_CREATE_SUB_KEY = &H4
    Private Const SYNCHRONIZE = &H100000
    Private Const STANDARD_RIGHTS_ALL = &H1F0000
    Private Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or KEY_CREATE_LINK) And (Not SYNCHRONIZE))
    Private Const ERROR_SUCCESS = 0
    Private Const REG_SZ = 1
    
    Private Const HKEY_LOCAL_MACHINE = &H80000002
    Private Const HKEY_CLASSES_ROOT = &H80000000
    Private Const HKEY_CURRENT_CONFIG = &H80000005
    Private Const HKEY_CURRENT_USER = &H80000001
    
    Public Enum enumHIVE
        eHKEY_LOCAL_MACHINE = HKEY_LOCAL_MACHINE
        eHKEY_CURRENT_USER = HKEY_CURRENT_USER
        eHKEY_CLASSES_ROOT = HKEY_CLASSES_ROOT
    End Enum
    
    Public Function GetRegistryValue(pHive As enumHIVE, p_strKey As String, p_strValue As String) As String
        Dim lngKey As Long
        Dim lngRet As Long
        Dim strBuffer As String
        
        lngRet = RegOpenKey(pHive, p_strKey, lngKey)
        
        If lngRet = ERROR_SUCCESS Then
            strBuffer = Space(255)
            lngRet = RegQueryValueEx(lngKey, p_strValue, 0, REG_SZ, ByVal strBuffer, Len(strBuffer))
            If lngRet = ERROR_SUCCESS Then
                GetRegistryValue = Left(strBuffer, InStr(strBuffer, vbNullChar) - 1)
            End If
            Call RegCloseKey(lngKey)
        End If
    End Function
    Then you can use this function like this:
    Code:
    Private Sub Command1_Click()
        Dim strValue As String
        
        strValue = GetRegistryValue(eHKEY_CURRENT_USER, "Control Panel\Desktop", "ScreenSaveActive")
        MsgBox "Function returned " & strValue
    End Sub

  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    There's a full example project on my site which demonstrates how to save and retrieve strings and dwords. http://www.parksie.uklinux.net/registry.zip
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  4. #4
    Guest
    Here is another way to see if the screen saver is enabled or not:

    Code:
    Public Const SPI_GETSCREENSAVEACTIVE = 16
    Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" _
    (ByVal uAction As Long, ByVal uParam As Long, lpvParam As Any, ByVal fuWinIni As _
    Long) As Long
    
    
    Private Sub Command1_Click()
    Dim blnReturn As Boolean
    Dim blnActive As Boolean
    Call SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, vbNull, blnReturn, 0)
    blnActive = blnReturn
    If blnActive Then
    MsgBox "Screen Saver is enabled."
    Else
    MsgBox "Screen Saver is disabled."
    End If
    End Sub

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    India
    Posts
    298
    actually my original query should have been


    kedaman,

    how do I use ur code to read:

    HKEY_CURRENT_USER\Control Panel\desktop\ScreenSaveUsePassword"

    I used regval(HKEY_CURRENT_USER\Control Panel\desktop\ScreenSaveUsePassword" )

    but was unable to retrieve the value.

    Thanx.

    Sorry abt the confusion!

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    Hmm, i thought i answered this once

    That's absolutely correct!
    Code:
    'to read
    yourstring = regval(HKEY_CURRENT_USER\Control Panel\desktop\ScreenSaveUsePassword") 
    'to write
    regval(HKEY_CURRENT_USER\Control Panel\desktop\ScreenSaveUsePassword") = yourstring
    but it depends if have that key, and the value ScreenSaveUsePassword
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    India
    Posts
    298
    Thats what I used but Im unable to retreive the value.

    I used:

    Code:
    Private Sub Command1_Click()
    Dim My_Str
        My_Str = RegVal("HKEY_CURRENT_USER\Control Panel\desktop\ScreenSaveUsePassword")
        MsgBox My_Str
    End Sub
    When the screensaver password wasn't set the msgbox was blank....thats fine,
    but when I set the screenaver password the message was an ascii char......

    any ideas???

    and yes kedaman, u told me abt using a property before, but was unable to retreive the right value, so thought I'd check!

  8. #8
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Whatdo you mean? You got an ascii char or did it fail to retrieve a value? Or was it the wrong one?
    If it's a DWORD it should returns a string with that binary data
    Run Regedit and check out if it reads that value, if not, there must be something corrupted

    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    India
    Posts
    298

    Question

    If the screensaver password is set, I get an ascii char......one sec, just converted it.....
    and it worked fine! thanx kedaman, for all the help......
    and everyone else whos helped me out here! dont know y I didn't think of this all this time!
    I wonder whats happening to me!!!

    [Edited by rammy on 09-20-2000 at 06:13 AM]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width