利用App對象的Path屬性返回可執(zhí)行文件的路徑進(jìn)行判斷。 Private Sub Form_Load() Dim a As String Dim b as String a=App.Path 獲得可執(zhí)行文件的路徑 b=Left(a,1) 取出第一個字符If b<>"A" Then MsgBox "本軟件只能在軟盤運(yùn)行!":End End Sub
右鍵單擊工具欄,在彈出的菜單中選擇部件,在控件中選擇Microsoft Internet Transfer Control 6.0,單擊確定。雙擊工具箱中新出現(xiàn)的Inet圖標(biāo),在啟動窗體中加入Internet Transfer控件Inet1 。如果你是電話撥號上網(wǎng),請使用該控件的缺省屬性;如果在Intranet上,可能需要提供代理服務(wù)器才能連接到Internet上,特別是有防火墻的Intranet,需將AccessType屬性設(shè)置為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) 調(diào)用OpenURL方法返回指定的HTML文檔,在打開的文件里寫入該文檔的源代碼,如果檢測到未與網(wǎng)絡(luò)連接則自動彈出撥號連接窗口,連接后程序才繼續(xù)運(yùn)行。 Close #1 Open "c:\password.txt" For Binary As #2 打開文件準(zhǔn)備查找關(guān)鍵字 lo=LOF(2) 獲取password.txt的大小 text=String(lo," ") 設(shè)定text的長度 Get #2,1,text 將整個文件讀入字符串變量 p1=InStr(1,text,"password:") 查找關(guān)鍵字password在文件中的位置 If p1=0 Then MsgBox "該文件未存放密碼":End 找不到關(guān)鍵字則函數(shù)返回0值 p2=p1+Len("password") 計算密碼的位置 p=Mid(text,p2,4) 取出4位數(shù)的密碼,注意p2須定義為Long Close #2 Kill("c:\password.txt") 密碼已取出,刪除臨時文件 a=InputBox("請輸入密碼") If a<>p Then MsgBox "密碼錯誤":End End Sub