Log in

View Full Version : [SOLVED:] custom .tlb file, same location?



Movian
01-05-2015, 07:09 AM
Hey so my front end utilizes a custom tlb called Encryption.tlb (Implements encryption using salted SHA 512 for single sign (Have native SHA 256 in VBA but not native 512))

this is normally installed for a hand full of clients manually in a folder (C:\MyAppEncryption\Encryption.tlb) and is then registered by running a batch file.

I then normally release 2 versions of our system through our automated update system, one version that references that .tlb and another that does not....

this 2 fork release is time consuming and frustrating and I finally got the go ahead to had everyone use the library so that we can have a single branch release.

So I want to set all our systems to automatically download, and register this file. so this leads to questions does the .tlb file need to be in a Fixed folder position? for example if I register it on my dev system in C:\MyAppEncryption\Encryption.tlb but then have client systems automaticaly download the .tlb and .dll to a sub folder in the app directoy C:\Program Files (X86)\MyApp\Encryption\Encryption.tlb will this still work? or will the front end be trying to locate it in C:\MyAppEncryption\Encryption.tlb or does the windows registration mean that it will look for it wherever windows tells it to ?

Once I have established this I need to find a way to have my front end check for admin permissions (as we need to register the file).

if they have admin permissions and if the tlb file does not exist in either location then I will download the files from a web server and I presume I can just shell the commands

C:\Windows\Microsoft.NET\Framework\v2.0.50727\Regasm.exe /tlb
C:\Windows\Microsoft.NET\Framework\v2.0.50727\regasm.exe /codebase

is there a way I can check to ensure that they were registered correctly ?


As always thanks in advance!

Movian
01-08-2015, 01:45 PM
Ok so as always I have been testing and researching since I posted and think I have found a solution....

I will run a background force un register if the file is located where it currently resides C:\Encryption\MyEncryption.dll

Then if the file does not exist in a subdirectory of the application currentproject.path & "\tools\MyEncryption.dll" it downloads the files from our web server automaticaly

the system then checks if the user is logged in with administrator permissions


Private Declare Function IsUserAnAdmin Lib "shell32" () As Long

if they are then it runs 2 shell commands


If IsUserAnAdmin Then
Shell "C:\Windows\Microsoft.NET\Framework\v2.0.50727\Regasm.exe " & CurrentProject.path & "/Tools/MyEncryption.dll /tlb:MyEncryption.tlb"
Shell "C:\Windows\Microsoft.NET\Framework\v2.0.50727\Regasm.exe " & CurrentProject.path & "/Tools/MyEncryption.dll /codebase"
Else
MsgBox "A process needs to be run as an administrator to ensure the correct operation of the system. Please run this application again with an administrator account", vbCritical, "Admin needed"
Exit Sub
End If


THEN i switch my usage of the package to late binding


'Dim My As MyEncryption.sha
'Set My = New MyEncryption.sha


Dim My As Object
Set My = CreateObject("MyEncryption.Sha")


Will let you know what I find, but if anyone spots an obvious problem with my thought process here I am thinking that this should work, and even if the files are not registered correctly will only cause a problem if they try and use THOSE features, where is if I add the files as a reference and they are not installed it creates crazy problems EVERYWHERE in the system....


any thoughts >?

Movian
01-08-2015, 04:23 PM
Final Subs

this code has passed internal testing but is not 100% finalized (needs more error handling added) but thought I would place it here for future reference and the assistance of others.

This code is on a splash screen on startup


Private Function tlbRegistered()Dim fso As New FileSystemObject
tlbRegistered = fso.FileExists(CurrentProject.path & "\Tools\MyEncryption.dll")
End Function


Private Sub GetTlb()
Dim errortext As String
Dim downloadflag As Boolean


downloadflag = DownloadFile("http://www.MyWebsite.com/Encryption/MyEncryption.dll", CurrentProject.path & "\Tools\MyEncryption.dll", OverwriteKill, errortext)
If downloadflag = False Then
MsgBox "There was a problem downloading a needed encryption file, please contact Technical support." & vbNewLine & vbNewLine & errortext, vbExclamation
End If
downloadflag = DownloadFile("http://www.MyWebsite.com/Encryption/MyEncryption.tlb", CurrentProject.path & "\Tools\MyEncryption.tlb", OverwriteKill, errortext)
If downloadflag = False Then
MsgBox "There was a problem downloading a needed encryption file, please contact Technical support." & vbNewLine & vbNewLine & errortext, vbExclamation
End If


End Sub


Private Sub RegisterTLB()
Dim command As String
If IsUserAnAdmin Then
If Debugging = True Then
command = "cmd /k C:\Windows\Microsoft.NET\Framework\v2.0.50727\Regasm.exe " & """" & CurrentProject.path & "\Tools\MyEncryption.dll " & """" & " /tlb:MyEncryption.tlb"
Else
command = "C:\Windows\Microsoft.NET\Framework\v2.0.50727\Regasm.exe " & """" & CurrentProject.path & "\Tools\MyEncryption.dll " & """" & " /tlb:MyEncryption.tlb"
End If
Shell command

If Debugging = True Then
command = "cmd /k C:\Windows\Microsoft.NET\Framework\v2.0.50727\Regasm.exe " & """" & CurrentProject.path & "\Tools\MyEncryption.dll " & """" & " /codebase"
Else
command = "C:\Windows\Microsoft.NET\Framework\v2.0.50727\Regasm.exe " & """" & CurrentProject.path & "\Tools\MyEncryption.dll " & """" & " /codebase"
End If
Shell command

If MsgBox("New files have been installed and this application needs to be closed and re opened to finish the installation, would you like to close this application now?", vbYesNo) = vbYes Then
Application.Quit
End If
Else
Dim fso As New FileSystemObject
fso.DeleteFile CurrentProject.path & "\Tools\MyEncryption.dll"
fso.DeleteFile CurrentProject.path & "\Tools\MyEncryption.tlb"
MsgBox "A process needs to be run as an administrator to ensure the correct operation of encryption features. Please run this application again with an administrator account", vbCritical, "Admin needed"
Exit Sub
End If
End Sub


Private Sub RemoveOldVersionIfPresent()
Dim fso As New FileSystemObject
If fso.FileExists("C:\MyEncryption\MyEncryption.dll") Then
Shell "C:\Windows\Microsoft.NET\Framework\v2.0.50727\Regasm.exe /u " & """" & CurrentProject.path & "\Tools\MyEncryption.dll " & """" & " /tlb:MyEncryption.tlb /codebase"
fso.DeleteFolder "C:\MyEncryption", True
End If
End Sub


Private Sub Form_Load()
If Not tlbRegistered Then
RemoveOldVersionIfPresent
GetTlb
RegisterTLB
End If
End Sub