Hey Guys,
I'm new to COM. I don't even know if what i'm trying to do is possible. I want clients to be able to change their registry settings from a server. The code that i'm using works as a vb standard exe. but then, when i make a new project and then use the same code to make a dll which i call on my ASP page, it does not change the registry setting. it does not return any error messages either. it just does n't take the variables i'm passing. below is the vb code that i am making a dll.
****in a module.bas
Public Const REG_SZ As Long = 1
Public Const REG_DWORD As Long = 4
Public Const REG_TYPE_STRING As Long = 1
Public Const REG_TYPE_DWORD As Long = 1
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003
Public Const HKEY_CLASSES_ROOT_NAME = "HKEY_CLASSES_ROOT"
Public Const HKEY_CURRENT_USER_NAME = "HKEY_CURRENT_USER"
Public Const HKEY_LOCAL_MACHINE_NAME = "HKEY_LOCAL_MACHINE"
Public Const HKEY_USERS_NAME = "HKEY_USERS"
Public Const ERROR_NONE = 0
Public Const ERROR_BADDB = 1
Public Const ERROR_BADKEY = 2
Public Const ERROR_CANTOPEN = 3
Public Const ERROR_CANTREAD = 4
Public Const ERROR_CANTWRITE = 5
Public Const ERROR_OUTOFMEMORY = 6
Public Const ERROR_ARENA_TRASHED = 7
Public Const ERROR_ACCESS_DENIED = 8
Public Const ERROR_INVALID_PARAMETERS = 87
Public Const ERROR_NO_MORE_ITEMS = 259
Public Const KEY_ALL_ACCESS = &H3F
Public Const REG_OPTION_NON_VOLATILE = 0
Public Type tReturnValues
lvReturnValue As Variant
llErrorStatus As Long
End Type
Declare Function RegCloseKey _
Lib "advapi32.dll" _
(ByVal hKey As Long) _
As Long
Declare Function RegSetValueExString _
Lib "advapi32.dll" Alias "RegSetValueExA" _
(ByVal hKey As Long, _
ByVal lpValueName As String, _
ByVal Reserved As Long, _
ByVal dwType As Long, _
ByVal lpValue As String, _
ByVal cbData As Long) _
As Long
Declare Function RegSetValueExLong _
Lib "advapi32.dll" Alias "RegSetValueExA" _
(ByVal hKey As Long, _
ByVal lpValueName As String, _
ByVal Reserved As Long, _
ByVal dwType As Long, _
lpValue As Long, _
ByVal cbData As Long) _
As Long
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
'Returns 0 if the Save was successful.
Public Reg_Ret_Val As Long
****in a class.cls
Public Function SetValueKey(psRootKey As String, psKeyName As String, psValueName As String, pvValueSetting As Variant, plValueType As Long) As Long
Dim llRetVal As Long 'result of the SetValueEx function
Dim lhKey As Long 'handle of open key
Dim llRootKey As Long
'Find the root key
llRootKey = GetRootKey(psRootKey)
'set return value prior to errors
SetValueKey = ERROR_NONE
'open the specified key
llRetVal = RegOpenKeyEx(llRootKey, psKeyName, 0, KEY_ALL_ACCESS, lhKey)
If llRetVal <> 0 Then
'an error has occurred
SetValueKey = llRetVal
Exit Function
End If
'write the value
llRetVal = SetValueEx(lhKey, psValueName, plValueType, pvValueSetting)
If llRetVal <> 0 Then
'an error has occurred
SetValueKey = llRetVal
Exit Function
End If
'Close the specified key
RegCloseKey (lhKey)
End Function
Private Function SetValueEx(ByVal hKey As Long, sValueName As String, lType As Long, vValue As Variant) As Long
Dim lValue As Long
Dim sValue As String
Select Case lType
Case REG_SZ
sValue = vValue & Chr$(0)
SetValueEx = RegSetValueExString(hKey, sValueName, 0&, lType, sValue, Len(sValue))
Case REG_DWORD
lValue = vValue
SetValueEx = RegSetValueExLong(hKey, sValueName, 0&, lType, lValue, 4)
End Select
End Function
Private Function GetRootKey(psRootKey As String) As Long
'Find the Root Key
Select Case Trim(UCase(psRootKey))
Case HKEY_CLASSES_ROOT_NAME
GetRootKey = HKEY_CLASSES_ROOT
Case HKEY_CURRENT_USER_NAME
GetRootKey = HKEY_CURRENT_USER
Case HKEY_LOCAL_MACHINE_NAME
GetRootKey = HKEY_LOCAL_MACHINE
Case HKEY_USERS_NAME
GetRootKey = HKEY_USERS
End Select
End Function
****in my ASP script
dim ObjReference
Set ObjReference = Server.CreateObject("Project1.Class1"
ObjReference.SetValueKey "HKEY_CURRENT_USER", "Software\ADOBE\Acrobat PDFwriter", "PDFFileName", "c:\pdfwriter\test.pdf", 1
Response.Write "done"
you can change the HKEY_CURRENT_USER key and other variable to fit your test environment. For some reason, this code does not work on the dll level. I have registered the dll using the regsvr32 command. i don't know if there are some settings I need to mess with on the server. Don't know what else to do. Someone please help.
I'm new to COM. I don't even know if what i'm trying to do is possible. I want clients to be able to change their registry settings from a server. The code that i'm using works as a vb standard exe. but then, when i make a new project and then use the same code to make a dll which i call on my ASP page, it does not change the registry setting. it does not return any error messages either. it just does n't take the variables i'm passing. below is the vb code that i am making a dll.
****in a module.bas
Public Const REG_SZ As Long = 1
Public Const REG_DWORD As Long = 4
Public Const REG_TYPE_STRING As Long = 1
Public Const REG_TYPE_DWORD As Long = 1
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003
Public Const HKEY_CLASSES_ROOT_NAME = "HKEY_CLASSES_ROOT"
Public Const HKEY_CURRENT_USER_NAME = "HKEY_CURRENT_USER"
Public Const HKEY_LOCAL_MACHINE_NAME = "HKEY_LOCAL_MACHINE"
Public Const HKEY_USERS_NAME = "HKEY_USERS"
Public Const ERROR_NONE = 0
Public Const ERROR_BADDB = 1
Public Const ERROR_BADKEY = 2
Public Const ERROR_CANTOPEN = 3
Public Const ERROR_CANTREAD = 4
Public Const ERROR_CANTWRITE = 5
Public Const ERROR_OUTOFMEMORY = 6
Public Const ERROR_ARENA_TRASHED = 7
Public Const ERROR_ACCESS_DENIED = 8
Public Const ERROR_INVALID_PARAMETERS = 87
Public Const ERROR_NO_MORE_ITEMS = 259
Public Const KEY_ALL_ACCESS = &H3F
Public Const REG_OPTION_NON_VOLATILE = 0
Public Type tReturnValues
lvReturnValue As Variant
llErrorStatus As Long
End Type
Declare Function RegCloseKey _
Lib "advapi32.dll" _
(ByVal hKey As Long) _
As Long
Declare Function RegSetValueExString _
Lib "advapi32.dll" Alias "RegSetValueExA" _
(ByVal hKey As Long, _
ByVal lpValueName As String, _
ByVal Reserved As Long, _
ByVal dwType As Long, _
ByVal lpValue As String, _
ByVal cbData As Long) _
As Long
Declare Function RegSetValueExLong _
Lib "advapi32.dll" Alias "RegSetValueExA" _
(ByVal hKey As Long, _
ByVal lpValueName As String, _
ByVal Reserved As Long, _
ByVal dwType As Long, _
lpValue As Long, _
ByVal cbData As Long) _
As Long
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
'Returns 0 if the Save was successful.
Public Reg_Ret_Val As Long
****in a class.cls
Public Function SetValueKey(psRootKey As String, psKeyName As String, psValueName As String, pvValueSetting As Variant, plValueType As Long) As Long
Dim llRetVal As Long 'result of the SetValueEx function
Dim lhKey As Long 'handle of open key
Dim llRootKey As Long
'Find the root key
llRootKey = GetRootKey(psRootKey)
'set return value prior to errors
SetValueKey = ERROR_NONE
'open the specified key
llRetVal = RegOpenKeyEx(llRootKey, psKeyName, 0, KEY_ALL_ACCESS, lhKey)
If llRetVal <> 0 Then
'an error has occurred
SetValueKey = llRetVal
Exit Function
End If
'write the value
llRetVal = SetValueEx(lhKey, psValueName, plValueType, pvValueSetting)
If llRetVal <> 0 Then
'an error has occurred
SetValueKey = llRetVal
Exit Function
End If
'Close the specified key
RegCloseKey (lhKey)
End Function
Private Function SetValueEx(ByVal hKey As Long, sValueName As String, lType As Long, vValue As Variant) As Long
Dim lValue As Long
Dim sValue As String
Select Case lType
Case REG_SZ
sValue = vValue & Chr$(0)
SetValueEx = RegSetValueExString(hKey, sValueName, 0&, lType, sValue, Len(sValue))
Case REG_DWORD
lValue = vValue
SetValueEx = RegSetValueExLong(hKey, sValueName, 0&, lType, lValue, 4)
End Select
End Function
Private Function GetRootKey(psRootKey As String) As Long
'Find the Root Key
Select Case Trim(UCase(psRootKey))
Case HKEY_CLASSES_ROOT_NAME
GetRootKey = HKEY_CLASSES_ROOT
Case HKEY_CURRENT_USER_NAME
GetRootKey = HKEY_CURRENT_USER
Case HKEY_LOCAL_MACHINE_NAME
GetRootKey = HKEY_LOCAL_MACHINE
Case HKEY_USERS_NAME
GetRootKey = HKEY_USERS
End Select
End Function
****in my ASP script
dim ObjReference
Set ObjReference = Server.CreateObject("Project1.Class1"
ObjReference.SetValueKey "HKEY_CURRENT_USER", "Software\ADOBE\Acrobat PDFwriter", "PDFFileName", "c:\pdfwriter\test.pdf", 1
Response.Write "done"
you can change the HKEY_CURRENT_USER key and other variable to fit your test environment. For some reason, this code does not work on the dll level. I have registered the dll using the regsvr32 command. i don't know if there are some settings I need to mess with on the server. Don't know what else to do. Someone please help.