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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Register DLL in the registry 1

Status
Not open for further replies.

swetham

Programmer
May 5, 2010
257
0
0
DE
I want to check whether a dll is registered on the client machine or not, if not it should be registered. to check whether the dll is registered or not i wrote the code as,

Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal _
lpLibFileName As String) As Long
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long

Function IsDLLAvailable(ByVal DllFilename As String) As Boolean
Dim hModule As Long

' attempt to load the module
hModule = LoadLibrary(DllFilename)
If hModule > 32 Then
FreeLibrary(hModule) ' decrement the DLL usage counter
IsDLLAvailable = True
End If
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If IsDLLAvailable("SHDOCVW.dll") Then
MsgBox("OK")
Else
Beep()
MsgBox(Err.LastDllError)
End If
End Sub



Now i want to add a dll in registry using vb.net code, how to do this? and what is the path where the dll's are stored in the registry editor?
 
I know it's not exactly what you asked, but you could just shell out to regsvr32 to register the DLL....

cheers,

Paul.
 
Thank you so much for the reply,Normally where are the .net dll's stored ie path in windows?
and what is the path in the registry editor? How to shell out to regsvr32 through vb.net code?
 
Actually you could try run a Process rather than start a shell.... either should work. Process example below. (I think this is now the preferred method of starting external processes from VB)




Note that the executing user must have permission to register DLLs.

You dont need to worry about what path etc to store the DLL in the registry - regsvr32 will take care of that for you.


Also I suggest you retest for the DLL to ensure it installed OK.



*** THIS IS NOT TESTED ***

Code:
Dim p As New Process()

p.StartInfo.FileName = C:\WINDOWS\system32\regsvr32.exe



' The /s argument stops regsvr32 from popping up anything on screen
' Put your DLL here

p.StartInfo.Arguments = "/s " & "c:\your_path\yourdll.dll"



p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardOutput = True


p.StartInfo.CreateNoWindow = True

p.Start()
*** THIS IS NOT TESTED ***



 
I will try it, where are all the .net dll's stored ie,path?
 
I dont think it matters... you could just put DLL in your own application path and register it there....
 
Excuse me for asking this question. Actually my need is when my application executable is installed on other machine it needs 2 dll's say a.dll and b.dll and whenever the system gets booted the exe should run automatically.

What i did was, in my code i have created a registry key in HKEY_LOCAL_MACHINE\Software\\Microsoft\\Windows\\CurrentVersion\\Run with the executable path. Now i dont want to create setup file. If i copy and paste only the exe it is showing errors where the dlls are required. I want to add dll's in the registry (in the program first it will check whether the dll's are registered in the machine or not and second it will check the exe registry key).

Actually i am a bit confused, my problems are,
1) If the required dll's are registered on the machine, does the exe run correctly?

2)The code which i posted first is checking the dll's in the project folder.

3) Is there any other way or what i am following is correct?
 
Yeah I think you are on the right track...

So,

1. you program starts autmatically on bootup.

2. Your program checks if a DLL is registed.

3. If its not registered then it registers the DLL using the code above.

To do this, all you need is the path to the DLL on the client machine. I can't tell you where these DLLs are on your client machine - you'll need to look at the machines and find the required files.

4. Program continues once DLLs are registered.



I'm not sure why you are trying to write the DLL to the registry... regsvr will register the DLL for you.

Why is the program checking the exe registry key? If you create an entry in HKLM\...\Run, Windows will execute that on bootup. Why do you need to check that exe key again?
 
I am checking the exe key because some people are deleting the key. I have one doubt,

If the dll's are registered on the client machine, does the exe works if i copy and paste only the exe? and the code which you gave above creates the dll in the specified path?

In general what is the procedure to run the exe on the client machine without using setup project?
 
The code which i have placed first is not working when i create a new project and check whether the code is registered or not. what is the procedure to check whether the dll's are registered ie, in c:/windows/assembly it is present or not?
 
I'm sorry, i'm getting a little confused now.

I thought your code already checks if the DLLs are registered?

If they are not registered and you need to register them, you should be able to do that by passing the DLL file path to regsvr32 using the code above. I dont know what the path is for your DLLs - it depends where you put the DLLs when you copy them to the client machine. If they are standard Windows DLLs, then you just need to find out where those files are stored on the client PCs.

If you are trying to check does the DLL file exist on the disk, then you could use something like

Code:
If System.IO.File.Exists("c:\your_path\yourdll.dll") Then

   ' do something here ie register the DLL or set a variable

End If
[code]

cheers,

Paul
 
As said before i am having a application and the application uses 2 dlls which i have added to the application using "add reference". can you please tell me the procedure to run the executable on the client machine without creating the setup ie,steps to follow for checking and adding dll's?

1)check whether the dll exist or not,
Code:
If System.IO.File.Exists("c:\your_path\yourdll.dll") Then

   ' do something here ie register the DLL or set a variable

End If
[code]

2) If not register dll,

How to do this?


Is this procedure correct?
 
ok I think I understand now...

You added the DLLs to your .NET build environment.

Are these standard .NET DLLs or are you registering customised DLLs?

Assuming they are standard .NET DLLs, then you dont need to register them on the client machine. Once the correct version of .NET framework is installed on the client machine, then all the required DLLs will already be there.

If .NET framework is not present, you will not be able to run .NET applications.



If this is a custom DLL (one that will be distributed with your application), then register it using the regsvr32 as we talked about above.


 
Thank you soo much for your support, at last my lead said to do using setup project. Now i got it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top