How to register a COM DLL from a Windows application using vb.net in windows 7
At first build a windows application and take a button known as buton1 and on clicking the write the following code :
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button2.Click
Registar_Dlls("Full Path Of the com Dll")
End Sub
Now this is the main function which will register the com dll file given below
Public Shared Sub Registar_Dlls(filePath As String)Try
''/s' : Specifies regsvr32 to run silently and to not display any message boxes.
Dim arg_fileinfo As String = """" & filePath & """"
Dim reg As New Process()
'This file registers .dll files as command components in the registry.
reg.StartInfo.FileName = "regsvr32.exe"
reg.StartInfo.Arguments = arg_fileinfo
reg.StartInfo.UseShellExecute = False
reg.StartInfo.CreateNoWindow = True
reg.StartInfo.RedirectStandardOutput = True
reg.Start()
reg.WaitForExit()
reg.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Now to register a com dll you have to run the created exe as administrator forcefully by coding .So to do this we have add a app.manifast file to our project and have to write the following code :
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
</asmv1:assembly>