wmz 发表于 2005-10-27 13:30:00

如何注册控件

<DIV>各位大侠,我在MJTD里下载了自动注册控件的函数,倒是方便了不少.如下例:</DIV>
<DIV>Sub TEST()<BR>&nbsp;&nbsp; Dim filename As String<BR>&nbsp;&nbsp; filename = "d:\vb98\vba6.dll"<BR>&nbsp;&nbsp; Call AutoRegFile(filename) '调用AutoRegFile函数自动注册控件<BR>End Sub<BR>Function AutoRegFile(filename As String)<BR>&nbsp; '自动注册控件<BR>&nbsp; '语法:(AutoRegFile FileName)<BR>&nbsp; '参数:FileName:文件名,必须包含路径<BR>&nbsp; Dim reged As Boolean<BR>&nbsp; Dim RegFile1 As String<BR>&nbsp; Dim RegFile2 As String<BR>&nbsp; Dim BeReg As String<BR>&nbsp; Dim RetVal<BR>&nbsp; BeReg = Dir(filename)<BR>If BeReg &lt;&gt; "" Then<BR>&nbsp; RegFile1 = Environ("windir") &amp; "\system\regsvr32.exe "<BR>&nbsp; RegFile2 = Environ("windir") &amp; "\system32\regsvr32.exe "<BR>&nbsp; If Dir(RegFile1) &lt;&gt; "" Or Dir(RegFile2) &lt;&gt; "" Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Dir(RegFile1) &lt;&gt; "" Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RegFile1 = RegFile1 &amp; "/s" &amp; " " &amp; BeReg<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RetVal = Shell(RegFile1, 1)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RegFile2 = RegFile2 &amp; "/s" &amp; " " &amp; BeReg<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RetVal = Shell(RegFile2, 1)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<BR>&nbsp; Else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "找不到regsvr32.exe文件,你可能无法使用本软件!", vbCritical, "无法自动注册控件"<BR>&nbsp; End If<BR>Else<BR>&nbsp; MsgBox "找不到控件文件!", vbCritical, "无法自动注册控件"<BR>End If<BR>End Function</DIV>
<DIV>现在的问题是:如何判断该控件是否已经注册呢?即如果上面的过程这样写</DIV>
<DIV>Sub TEST()<BR>&nbsp;&nbsp; Dim filename As String<BR>&nbsp;&nbsp; filename = "d:\vb98\vba6.dll"</DIV>
<DIV>&nbsp; if&nbsp;&lt;该控件尚未注册&gt; &nbsp;then</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; Call AutoRegFile(filename) '调用AutoRegFile函数自动注册控件</DIV>
<DIV>&nbsp;&nbsp;endif <BR>End Sub</DIV>
<DIV>这&lt;该控件尚未注册&gt; 里的代码如何写呢?<BR></DIV>
页: [1]
查看完整版本: 如何注册控件