之前有用到Teechart控件测试与应用,是在网上下载的,在此也特别感谢他,
他把OCX控件封装到了程序里面,一键注册使用,开启了我的最初的使用,
后面我也一直没有去研究过这类具体要怎样弄,
直到前几天,MERS疫情,待在家中,我需要把现在的程序优化以后,虽然之前那位仁兄做得挺好,
我还是要考虑下我的话怎么封装和释放需要的OCX或DLL等文件,
如图,只是以Teechart为例:
添加资源如下图:
注册代码如下:
Try
If xuanzhe_1.Checked = True Then '32bit
Dim b() As Byte = My.Resources.TeeChart8 '(1._1 '将资源文件转换为Byte()
Dim s As IO.Stream = File.Create("c:\Windows\System32\TeeChart8.ocx") '设定文件创建位置
s.Write(b, 0, b.Length) '文件写入)
s.Close() '关闭文件
Shell("regsvr32.exe /s """ & "c:\Windows\System32\TeeChart8.ocx", AppWinStyle.NormalFocus)
MsgBox("注册成功")
Else
Dim b() As Byte = My.Resources.TeeChart8 '(1._1 '将资源文件转换为Byte()
Dim s As IO.Stream = File.Create("c:\Windows\SysWOW64\TeeChart8.ocx") '设定文件创建位置
s.Write(b, 0, b.Length) '文件写入)
s.Close() '关闭文件
Shell("regsvr32.exe /s """ & "c:\Windows\SysWOW64\TeeChart8.ocx", AppWinStyle.NormalFocus)
MsgBox("x64 注册成功")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
卸载代码如下,注(这里卸载并没有考虑去删除之前释放拷贝到系统下的文件)
Try
If xuanzhe_1.Checked = True Then '32bit
Shell("regsvr32.exe /u /s """ & "c:\Windows\System32\TeeChart8.ocx", AppWinStyle.NormalFocus)
MsgBox("卸载成功")
Else
Shell("regsvr32.exe /u /s """ & "c:\Windows\SysWOW64\TeeChart8.ocx", AppWinStyle.NormalFocus)
MsgBox("x64 卸载成功")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
总图如下,一个单一程序便可以释放并注册想要的东西了:
扫描二维码关注公众号,回复:
9116772 查看本文章