有些網頁上的東西(圖片、影音檔 ...)
網頁不讓你右鍵或FlashGet下載
這裡教你 當你網頁開完下載100%後,直接從 Temporary Internet Files 裡挖
PHP 語法:
Public Function GetCachePath(lpszUrl As String) As String
Dim dwEntrySize As Long
Dim lpCacheEntry As INTE_CACHE_ENTRY_INFO '宣告一個Temporary Internet Files資訊結構 變數
Dim tarr() As Byte
Call GetUrlCacheEntryInfo(StrPtr(lpszUrl), ByVal 0, dwEntrySize) '呼叫獲取Temporary Internet Files 資訊函式
If dwEntrySize > 0 Then '如果可獲得資訊 (不是空的)
ReDim tarr(0 To dwEntrySize) '配置一個可容納該資訊的 空間
Call GetUrlCacheEntryInfo(StrPtr(lpszUrl), tarr(0), dwEntrySize) '再執行一次,利用前面的 空間 接收
CopyMem ByVal lpCacheEntry, tarr(0), Len(lpCacheEntry) '將那份Byte結構的資訊 利用記憶體 複印方式,存成 Temporary Internet Files資訊結構
GetCachePath = SysAllocString(lpCacheEntry.lpszLocalFileName) '將其中的本機路徑取出,SysAllocString是用來"溝通" VB 與 系統 字串傳遞的API函式 (藉由記憶體位址)
GetCachePath = StrConv(GetCachePath, vbFromUnicode) '將UniCode轉碼成本機ANSI字碼
Else
'getcachepath =""
End If
End Function
有人或許質疑為何要用 StrConv
那是因為以下的 GetUrlCacheEntryInfo 是 for UniCode的 "W"字尾 API函式
如沒有轉換
"C:\FF\A.B"
會變成
"C:\FF\A.B"
如何使用呢?
PHP 語法:
Dim sMyURL as String, sPathFileName as String
Dim fso As New Scripting.FileSystemObject
'程式為了適應UniCode路徑檔名,我們使用MS Script Control 物件類別,來做檔案處理
',如沒有在VB IDE裡先行引用的話,需改為
'Dim fso As Object
'Set fso = CreateObject("Scripting.FileSystemObject")
sMyURL = "http://A.B.C.D/E/ooo.xxx"
sMyURL = GetCachePath(sMyURL)
If Len(sMyURL) > 0 Then
sPathFileName = "X:\ooo.xxx" '新的名稱
fso.CopyFile sMyURL, sPathFileName '從Temporary Internet Files 裡複製出來
End If
以下是會用到的函式 與 資料結構
PHP 語法:
Public Declare Function GetUrlCacheEntryInfo Lib "wininet.dll" Alias "GetUrlCacheEntryInfoW" ( _
ByVal szUrlName As Long, _
ByRef lpCacheEntryInfo As Any, _
ByRef lpdwCacheEntryInfoBufferSize As Long) As Long
Public Declare Function SysAllocString Lib "oleaut32.dll" (ByVal pOlechar As Long) As String
Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Public Type INTE_CACHE_ENTRY_INFO
dwStructSize As Long
lpszSourceUrlName As Long
lpszLocalFileName As Long
CacheEntryType As Long
dwUseCount As Long
dwHitRate As Long
dwSizeLow As Long
dwSizeHigh As Long
LastModifiedTime As FILETIME
ExpireTime As FILETIME
LastAccessTime As FILETIME
LastSyncTime As FILETIME
lpHeaderInfo As Long
dwHeaderInfoSize As Long
lpszFileExtension As Long
dwReserved As Long
End Type
Public Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory" ( _
Destination As Any, _
Source As Any, _
ByVal Length As Long)
所以只要知道了該文件的WWW URL
那就能執行以上動作,從 Temporary Internet Files 裡複製出來