利用App对象的Path属性返回可执行文件的路径进行判断。 Private Sub Form_Load() Dim a As String Dim b as String a=App.Path 获得可执行文件的路径 b=Left(a,1) 取出第一个字符If b<>"A" Then MsgBox "本软件只能在软盘运行!":End End Sub
右键单击工具栏,在弹出的菜单中选择部件,在控件中选择Microsoft Internet Transfer Control 6.0,单击确定。双击工具箱中新出现的Inet图标,在启动窗体中加入Internet Transfer控件Inet1 。如果你是电话拨号上网,请使用该控件的缺省属性;如果在Intranet上,可能需要提供代理服务器才能连接到Internet上,特别是有防火墙的Intranet,需将AccessType属性设置为icNamedProxy(2),再加入代码Inet1.Proxy="myProxyName"。
在程序中加入以下代码:
Private Sub Form1_Load() Dim lo As Variant Dim text As String Dim p1 As Long Dim p2 As Long Dim p As String Dim website As String website=" http://www.home.com/mypage.htm " Open ("c:\password.txt") For Output As #1 建立文本文件放置HTML文档 Write #1,Inet1.OpenURL(website) 调用OpenURL方法返回指定的HTML文档,在打开的文件里写入该文档的源代码,如果检测到未与网络连接则自动弹出拨号连接窗口,连接后程序才继续运行。 Close #1 Open "c:\password.txt" For Binary As #2 打开文件准备查找关键字 lo=LOF(2) 获取password.txt的大小 text=String(lo," ") 设定text的长度 Get #2,1,text 将整个文件读入字符串变量 p1=InStr(1,text,"password:") 查找关键字password在文件中的位置 If p1=0 Then MsgBox "该文件未存放密码":End 找不到关键字则函数返回0值 p2=p1+Len("password") 计算密码的位置 p=Mid(text,p2,4) 取出4位数的密码,注意p2须定义为Long Close #2 Kill("c:\password.txt") 密码已取出,删除临时文件 a=InputBox("请输入密码") If a<>p Then MsgBox "密码错误":End End Sub