|
-
Nov 10th, 2007, 08:00 AM
#1
Thread Starter
Fanatic Member
[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.
-
Nov 10th, 2007, 08:34 AM
#2
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:
Public Function RegWriteDword(lngHKey As Long, strSubKey As String, strValueName As String, lngDwordDat As Long) As Long
'Create the subkey, value name and respective DWORD value.
Dim lngRetval As Long
Dim lngKeyHandle As Long
'Set the default return value.
RegWriteDword = ERROR_FAILED '999
'Create the key.
If RegCreateKeyEx(lngHKey, strSubKey, 0&, 0&, REG_OPTION_NON_VOLATILE, KEY_CREATE_SUB_KEY, ByVal 0&, lngKeyHandle, lngRetval) = ERROR_SUCCESS Then
'Open the new key.
If RegOpenKeyEx(lngHKey, strSubKey, 0&, KEY_SET_VALUE, lngKeyHandle) = ERROR_SUCCESS Then
'Write it to the registry, and return a code.
RegWriteDword = RegSetValueEx(lngKeyHandle, strValueName, 0&, REG_DWORD, lngDwordDat, Len(lngDwordDat))
End If
End If
'Close any key opened with RegCreateKeyEx.
Call RegCloseKey(lngKeyHandle)
End Function
-
Nov 10th, 2007, 08:46 AM
#3
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|