0

我有一个 VBScript,它导航到 Internet Explorer 页面,该页面在我的 Internet 临时文件夹中存储了一个名为“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

消息框键

4

2 回答 2

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"
于 2014-05-23T20:15:07.420 回答
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
于 2014-05-23T16:19:38.363 回答