PDA

Click to See Complete Forum and Search --> : registry key writing


digisol1
Nov 30th, 1999, 08:53 PM
I am whipped again... I have read and read and read trying to avoid posting to this place again. I really hate to bother other people with my problems but I am very new to programing (I am a technician tring to convert) and am having trouble with the following (very simple might I add) exe file
If someone could please look at it and see what is wrong I would be very thank full.

Option Explicit

Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, 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 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 RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
Private Const REG_CREATED_NEW_KEY = &H1
Private Const REG_OPENED_EXISTING_KEY = &H2
Private Const REG_OPTION_NON_VOLATILE = 0&
Private Const REG_OPTION_VOLATILE = &H1
Private Const KEY_ALL_ACCESS = &H3F
Private Const REG_SZ = 1
Private Const KEY_SET_VALUE = &H2
Private Const ERROR_SUCCESS = 0&
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const HKEY_CURRENT_USER = &H80000001
Private Const REG_BINARY = 3 ' Free form binary
Private Const REG_DWORD = 4 ' 32-bit number

'this part of the code works great as you see in the form load area
' the addtostartup commands will write the strings to the polyakoff
'key if it exists
Public Sub AddToStartup(pstrProgramName As String, pstrProgramPath As String)
Dim strKey As String
Dim lRet As Long
Dim lngKeyHandle As Long
strKey = "Software\Polyakoff\JIT\Scheduler"
lRet = RegOpenKeyEx(HKEY_CURRENT_USER, strKey, 0, KEY_SET_VALUE, lngKeyHandle)
If lRet = ERROR_SUCCESS Then
lRet = RegSetValueEx(lngKeyHandle, pstrProgramName, 0, REG_SZ, ByVal pstrProgramPath, Len(pstrProgramPath))
If lRet = ERROR_SUCCESS Then RegCloseKey lngKeyHandle
End If
End Sub

'this is the part of the code that the problem lies in, this
'should create the polyakoff keys so the addtostartup commands will work

Public Sub CreateKey(hKey As Long, strPath As String)
Dim hCurKey As Long
Dim lRegResult As Long
lRegResult = RegCreateKey(hKey, strPath, hCurKey)
If lRegResult <> ERROR_SUCCESS Then
End If

lRegResult = RegCloseKey(hCurKey)

End Sub

Private Sub Form_Load()
On Error GoTo 600
'this will write the schedule information to the registry so that
' the program will work if another user logs in.
If Command$ = "/check" Then
CreateKey "HKEY_CURRENT_USER", "software\polyakoff\JIT\Scheduler"
AddToStartup "DAT", "c:\citrix\schedule.sch"
AddToStartup "LOG", "c:\citrix\citrix.log"
GoTo 800
End If
600 Shell ("c:\citrix\wfica32 c:\citrix\logon.ica")
800 Unload Me
End Sub

Please help if you can

Aaron Young
Nov 30th, 1999, 09:14 PM
In your Form_Load Event you have Double-Quotes "" around HKEY_CURRENT_USER making it a String, instead of using the Constant.

Try:
CreateKey HKEY_CURRENT_USER, "software\polyakoff\JIT\Scheduler"

------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net

digisol1
Nov 30th, 1999, 09:45 PM
Thank you very much I worked on this code for approx 10-15 hours I am a real fighter kinda like a pitbull, I don't give up. I must have written that section at least 5 different ways but to no avial. Thank you again.