Results 1 to 3 of 3

Thread: [RESOLVED] dWord

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Resolved [RESOLVED] dWord

    Option Explicit

    Code:
    Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal HKey As Long) As Long
    Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal HKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal HKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
    
    Private Sub SaveString(HKey As Long, Path As String, Name As String, Data As Variant)
    
    Dim KeyHandle As Long
    Dim RetVal As Long
    
    RetVal = RegCreateKey(HKey, Path, KeyHandle)
    RetVal = RegSetValueEx(KeyHandle, Name, 0&, 4, Data, 4) 'Will make it a dWord
    RetVal = RegCloseKey(KeyHandle)
    
    End Sub
    
    Public Sub Tick_Key()
    Debug.Print "Ticked"
    SaveString &H80000002, "System\CurrentControlSet\Control\LSA", "ForceGuest", 1
    
    End Sub
    
    Public Sub Untick_Key()
    Debug.Print "Unticked"
    SaveString &H80000002, "System\CurrentControlSet\Control\LSA", "ForceGuest", 0
    
    End Sub
    How come no matter what i do, it makes the value 2?

    If i set it to &HFFFFFFFF then it makes the value 3, but setting it to -1, brings it back to 2, that's so wierd.

    I'm trying to work out how to make this value swap between 1 & 0.

    Yes i've look and researched how to set dWords, but nothing has helped.

  2. #2
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: dWord

    Try setting "Data As Variant" to a Long. I also think you're missing out a step there. The handle from RegCreateKey refers to the "Subkey", not the "Value Name", which is the handle you actually need. This may give you ideas:
    vb Code:
    1. Public Function RegWriteDword(lngHKey As Long, strSubKey As String, strValueName As String, lngDwordDat As Long) As Long
    2. 'Create the subkey, value name and respective DWORD value.
    3.    Dim lngRetval     As Long
    4.    Dim lngKeyHandle  As Long
    5.  
    6. 'Set the default return value.
    7.    RegWriteDword = ERROR_FAILED '999
    8. 'Create the key.
    9.    If RegCreateKeyEx(lngHKey, strSubKey, 0&, 0&, REG_OPTION_NON_VOLATILE, KEY_CREATE_SUB_KEY, ByVal 0&, lngKeyHandle, lngRetval) = ERROR_SUCCESS Then
    10. 'Open the new key.
    11.       If RegOpenKeyEx(lngHKey, strSubKey, 0&, KEY_SET_VALUE, lngKeyHandle) = ERROR_SUCCESS Then
    12. 'Write it to the registry, and return a code.
    13.          RegWriteDword = RegSetValueEx(lngKeyHandle, strValueName, 0&, REG_DWORD, lngDwordDat, Len(lngDwordDat))
    14.       End If
    15.    End If
    16. 'Close any key opened with RegCreateKeyEx.
    17.    Call RegCloseKey(lngKeyHandle)
    18. End Function

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: dWord

    Thanks, setting it to a long fixed it. I kept trying integer and all sorts of other types that would fit it, but i never tried long!

    Nahh, I'm not, this key will always exist... if it doesn't well... the computer doesn't deserve to run my program =p.

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