Welcome !
         

 HTA FileExists doesn't work

Author Message
diego.torres.zamora

  • Total Posts : 13
  • Scores: 0
  • Reward points : 0
  • Joined: 11/15/2016
  • Status: offline
HTA FileExists doesn't work Thursday, January 05, 2017 6:59 PM (permalink)
0
Hello VBS-Gurus.
I'm trying to get a HTA to work. Therefore I need to have an INI-file und the directory of the HTA. So I used object.FileExists to make sure the file ist there. But I receive an error on running the Script in the line

If (FileOBJ.FileExists(iniFilePath)) Then
.
here is the complete sub:
Sub Window_OnLoad
    window.resizeto 350,350
    Dim equalPos
    Dim FileOBJ, iniFilePath, iniFile
    Dim iniQLW, iniZLW, iniPW, iniSectionQLW, iniSectionZLW, iniSectionPW, iniStream, iniArray, iniSplit
    
    FullName = replace(WorkTrueCrypt.commandLine,chr(34),"")  
    arrFN=split(FullName,"\")  
    FileName = arrFN(ubound(arrFN))  
    SourceDir=replace(FullName,FileName,"")
    iniFilePath = SourceDir & "ssTC.ini"
    'MsgBox iniFilepath
    Set FileOBJ = CreateObject( "Scripting.FileSystemObject" )
    If (FileOBJ.FileExists(iniFilePath)) Then
        Set iniFile = FileOBJ.OpenTextFile( iniFilePath, ForReading, False )
            Do While iniFile.AtEndOf Stream = False
                iniSteram = Trim(iniFile.ReadLine) & "|"
            Loop
        Set iniFile = Nothing
        iniArray = Split(iniStream,"|")
        For Each x in iniArray
            If InStr(x,"QuellLW=") = 1 Then
                equalPos = InStr(x,"=")+1
                iniQLW = Mid(x, equalPos,1)
            End If
            If InStr(x,"MountLW=") = 1 Then
                equalPos = InStr(x,"=")+1
                iniZLW = Mid(x, equalPos,1)
            End If
            If InStr(x,"MountPW=") = 1 Then
                equalPos = InStr(x,"=")+1
                iniPW = Mid(x, equalPos,1)
            End If
        Next
    Else
        MsgBox "INI-datei nicht vorhanden!",vbError,"Fehler"
    End If
    innerhtml.usbPfd = iniQLW
    innerhtml.mntPfd = iniZLW
    innerhtml.mountPW = iniPW
    
End Sub

Can anyone explain this or help me with this problem?
Thank you in advance and have a nice day.
Greetings
Diego
 
p.s. Non omnia possum omnes!
 
#1
    59cobalt

    • Total Posts : 2608
    • Scores: 253
    • Reward points : 0
    • Joined: 7/17/2011
    • Status: offline
    Re:HTA FileExists doesn't work Friday, January 06, 2017 1:53 AM (permalink)
    0
    Do we really need to ask for the error. Every. Single. Time?
     
    #2
      diego.torres.zamora

      • Total Posts : 13
      • Scores: 0
      • Reward points : 0
      • Joined: 11/15/2016
      • Status: offline
      Re:HTA FileExists doesn't work Sunday, January 08, 2017 6:35 PM (permalink)
      0
      Hello 59cobalt.
      I didn't post the error message because I need to translate it from german to english. But I'll try. The error number is 800A0005 and the error message is something like: Invalid procedure call or invalid argument.

       
      Greetings
      Diego
       
      p.s. Non omnia possum omnes!
       
      #3
        59cobalt

        • Total Posts : 2608
        • Scores: 253
        • Reward points : 0
        • Joined: 7/17/2011
        • Status: offline
        Re:HTA FileExists doesn't work Sunday, January 08, 2017 11:06 PM (permalink)
        0
        This is at least the third time that the line you claim produced the error turns out to be exactly one line before the one actually producing the error. Are you doing this on purpose? From now on please copy/paste error messages exactly as you receive them (including error number, error message, line number, EVERYTHING). Do NOT try to interpret them yourself.

        Now back to your actual problem. This is what causes the error:
        Set iniFile = FileOBJ.OpenTextFile( iniFilePath, ForReading, False )
        because you didn't define ForReading (see here for a more detailed explanation).
        You can just omit the second and third parameter, since you're using default values for them anyway:
        Set iniFile = FileOBJ.OpenTextFile(iniFilePath)
        With that said, there are some other adjustments you may want to make as well, since you're already using a FileSystemObject instance:
        Set FileOBJ = CreateObject("Scripting.FileSystemObject")
        FullName = Replace(WorkTrueCrypt.CommandLine, Chr(34), "")
        iniFilePath = FileOBJ.BuildPath(FileOBJ.GetParentFolderName(FullName), "ssTC.ini")
        If FileOBJ.FileExists(iniFilePath) Then
            Set iniFile = FileOBJ.OpenTextFile(iniFilePath)
            ...
        End If

         
        #4
          diego.torres.zamora

          • Total Posts : 13
          • Scores: 0
          • Reward points : 0
          • Joined: 11/15/2016
          • Status: offline
          Re:HTA FileExists doesn't work Sunday, January 08, 2017 11:41 PM (permalink)
          0
          Thank you 59cobalt. The problem with the line numbers where the error rises is my vbs/hta editor. It keeps me telling the error rises one lien before the problem and I recognized it now with your suggestions.
           
          <message edited by diego.torres.zamora on Monday, January 09, 2017 12:26 AM>
          Greetings
          Diego
           
          p.s. Non omnia possum omnes!
           
          #5
            Online Bookmarks Sharing: Share/Bookmark

            Jump to:

            Current active users

            There are 0 members and 1 guests.

            Icon Legend and Permission

            • New Messages
            • No New Messages
            • Hot Topic w/ New Messages
            • Hot Topic w/o New Messages
            • Locked w/ New Messages
            • Locked w/o New Messages
            • Read Message
            • Post New Thread
            • Reply to message
            • Post New Poll
            • Submit Vote
            • Post reward post
            • Delete my own posts
            • Delete my own threads
            • Rate post

            2000-2017 ASPPlayground.NET Forum Version 3.9