Reading a file in internet explorer temp folder

1.1k views Asked by At

I have A VBScript that navigates to an Internet Explorer page which stores a file called "123.txt" in my Temp internet Folder. In this text file is a line that reads "Key=1234567" I am trying to make a script that retrieves this key and displays it in a message box. My problem is that the temp folder is a virtual folder and the files cannot be read like a normal file.

       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 key

2

There are 2 answers

0
user3654095 On BEST ANSWER

As files in Temp Internet Files are usually renamed in reality. Therefore use the shell interfaces which will use the name you think it has.

This is the same as the columns you can turn on in Explorer details view.

This script dumps all shell properties for a objects in a folder. It does 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"
0
Bond On

It looks like you're using VB.NET. Here a VBScript example:

' 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