在Internet Explorer临时文件夹中读取文件

时间:2014-05-23 13:13:12

标签: internet-explorer vbscript virtualfilesystem

我有一个VBScript导航到Internet Explorer页面,该页面在我的Temp Internet Folder中存储一个名为“123.txt”的文件。在这个文本文件中有一行显示“Key = 1234567”我试图创建一个脚本来检索此密钥并将其显示在消息框中。我的问题是临时文件夹是一个虚拟文件夹,文件无法像普通文件一样被读取。

       Const TEMPORARY_INTERNET_FILES = &H20&


    Dim WshShell = CreateObject("WScript.Shell")



    Dim objShell = CreateObject("Shell.Application")
    Dim objFolder = objShell.Namespace(TEMPORARY_INTERNET_FILES)
    Dim objFolderItem = objFolder.Self





    Dim ie = CreateObject("InternetExplorer.Application")
    ie.visible = True
    ie.navigate2("myUrl")

    While (ie.busy)
        wscript.Sleep(1)
    End While

    Dim f As StreamReader
    Dim colItems = objFolder.Items
    For Each objItem In colItems

        If InStr(objItem.name, "123.txt") <> 0 Then
                            Dim sr As StreamReader = New StreamReader(Str(objFolderItem.path & "\" & objItem.name))
            Do While sr.Peek() >= 0
             dim line = sr.ReadLine()
             if(instr(line,"key")<>0) then 
                  key = line
             end if
            Loop
        End If
    Next

msgbox密钥

2 个答案:

答案 0 :(得分:0)

看起来你正在使用VB.NET。这是一个VBScript示例:

' Get the path to the temporary internet files folder...
strPath = objShell.Namespace(TEMPORARY_INTERNET_FILES).Self.Path

' Create an FSO...
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Check for the file's existence...
If objFSO.FileExists(strPath & "\123.txt") Then

    ' Read the first line...
    strLine = objFSO.OpenTextFile(strPath & "\123.txt").ReadLine()

    ' Split on '=' and display the second array element...
    MsgBox Split(strLine, "=")(1)

End If

答案 1 :(得分:0)

由于Temp Internet Files中的文件通常在实际中重命名。因此,请使用将使用您认为具有的名称的shell接口。

这与您可以在资源管理器详细信息视图中打开的列相同。

此脚本转储文件夹中对象的所有shell属性。它确实是TIF。

Set objShell = CreateObject("Shell.Application")
Set Ag=Wscript.Arguments
set WshShell = WScript.CreateObject("WScript.Shell")

'32 is Temp Internet Files
Set Fldr=objShell.NameSpace(32)
'Set Fldr=objShell.NameSpace(Ag(0))
Set FldrItems=Fldr.Items
Set fso = CreateObject("Scripting.FileSystemObject")


Set DeskFldr=objShell.Namespace(16)
FName=fso.buildpath(DeskFldr.self.path, "Folder Property List.txt")


Set ts = fso.OpenTextFile(FName, 8, true)


'Getting first 40 column names by passing null
For x = 0 to 40
    t1 = t1 & Fldr.GetDetailsOf(vbnull, x) & vbtab
Next
ts.write FLDR.self.path & vbcrlf
ts.Write T1 & vbcrlf
T1=""

'getting the first 40 column values for each item
For Each FldrItem in FldrItems
    For x = 0 to 40
        t1 = t1 & Fldr.GetDetailsOf(FldrItem, x) & vbtab
    Next
    t1=t1 & vbcrlf
    ts.Write T1
    T1=""
Next

msgbox FName & "has a tab delimited list of all properties"