Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with dll

Status
Not open for further replies.

nam4520

Programmer
Jan 7, 2003
14
US
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(&quot;Project1.Class1&quot;)
ObjReference.SetValueKey &quot;HKEY_CURRENT_USER&quot;, &quot;Software\ADOBE\Acrobat PDFwriter&quot;, &quot;PDFFileName&quot;, &quot;c:\pdfwriter\test.pdf&quot;, 1
Response.Write &quot;done&quot;

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.
 
VBScript passes Variants only. If you use ByVal on those parameters that are not modified by the DLL, I believe COM will &quot;marshall&quot; them to the proper specified data type. Alternative is to have an entry point(s) just for ASP using Variant. Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
This COM object will only run on the webserver. It won't change the registry on a local PC using the website. Is that your intention?
 
Hey Baddos,
That's my intention, to change the registry setting on a local PC. Why should n't it work? Is there another way to do it? thanks
 
Using a COM object will only have control over the webserver's computer. You could try doing an activex control, but I have no experience w/ them.
 
I have dumped the local computer idea. I'm no longer interested in having the dll access a local computer's registry from the server. But now, the dll doesn't work on the server machine either. it recognizes that the dll is there but won't do anything with the variables that i'm passing. I could type trash in there as variable and still, it will return no error. Thanks in advance to anyone who helps me with this
 
Hey Baddos,
I just registered it in the registry. How do you register it with component services? Anyway, I found that vbscript can interact with the registry by using the server.createobject(&quot;wscript.shell&quot;) code. This also works excellently when i run it in vb but not on vbscript. i'm getting this error below. I'm using an IIS server and my platform is windows 2000 professional. Please help. Maybe it's a permissions problem on my server.

Error Type:
WshShell.RegWrite (0x80070005)
Invalid root in registry key &quot;HKEY_CURRENT_USER\Software\ADOBE\Acrobat PDFwriter\PDFFileName&quot;.
/dll.asp, line 7



this is the code that i'm trying to execute

<%
dim WshShell
Set WshShell = Server.CreateObject(&quot;WScript.Shell&quot;)
WshShell.RegWrite &quot;HKEY_CURRENT_USER\Software\ADOBE\Acrobat PDFwriter\PDFFileName&quot;, &quot;c:\pdfwriter\test.pdf&quot;, &quot;REG_SZ&quot;
Response.Write &quot;done&quot;
%>

I want &quot;PDFFileName&quot; to go under the &quot;Acrobat PDFWriter&quot; key, under the column, &quot;Name&quot;. &quot;c:\pdfwriter\test.pdf&quot; should then go under the column, &quot;Data&quot;. REG_SZ is the type. Thanks

 
I can't help you, I am not familiar w/ programmatically editing the registry.

Sorry. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top