title: vbscript runtime error object variable not set when using object.writeline
body: <p>I am creating a script to download an update file ([server_path]\local.swf) from a remote server using vbscript. the script will be run through a windows command line and will accept parameters. one of these parameters is the new_hash, it contains the hash of the file to be downloaded. This hash will be used to compare with hash of the file that is already in my pc (c:\mcgfiles\avp\local.swf). If the same, log comments and do nothing. If not then download the local.swf and place it in a temporary folder c:\mcgfiles\avp-temp. Since the vbscript will be accessing an sftp server to dowload the file, I made some delays in the script and check if the file has been downloaded before proceeding to the next step. If the files is already in place, I will create a hash.txt in the same folder c:\mcgfiles\avp-temp, read it then compare to the hash passed through the script. Error occurs when running the script:</p>
  
  <p>vbscript runtime error object variable not set when using object.writeline</p>
  
  <p>here is my script:</p>
  
  <pre><code>Option Explicit
  Dim Arg, hostname, new_hash, file_version
  Dim obj, objLogActivity, objLogStatus, objLogProgram, objCurrHashFile, shellSFTP, WshShell
  Dim tmp, datestamp, datestamp2, logCommand, current_hash, comparison, updateAVP, logfile, commandfile, retryLocalSWF
  Dim tokenGenHash, retryHashTXT, tokenReadHash, objDownHashFile, downloaded_hash
  Set Arg = WScript.Arguments
  hostname = Arg(0)
  new_hash = Arg(1)
  file_version = Arg(2)
  tmp=now()
  datestamp = DatePart("yyyy",tmp) &amp; "-" &amp; Right("00" &amp; DatePart("m",tmp),2) &amp; "-" &amp; Right("00" &amp; DatePart("d",tmp),2)
  datestamp2 = DatePart("yyyy",tmp)&amp;Right("00" &amp; DatePart("m",tmp),2)&amp;Right("00" &amp; DatePart("d",tmp),2)&amp;Right("00" &amp; DatePart("H",tmp),2)&amp;Right("00" &amp; DatePart("n",tmp),2)&amp;Right("00" &amp; DatePart("s",tmp),2)
  
  Set obj = CreateObject("Scripting.FileSystemObject")
  Set objLogActivity = obj.CreateTextFile("C:\mcgfiles\logs\activity\activity_"&amp; hostname &amp;"_"&amp;datestamp&amp;".log")
  objLogActivity.Close
  Set objLogStatus = obj.CreateTextFile("C:\mcgfiles\logs\status\status_"&amp; hostname &amp;"_"&amp;datestamp&amp;".log")
  objLogStatus.Close
  If obj.FileExists("C:\mcgfiles\logs\program\program_"&amp;hostname&amp;"_"&amp;datestamp&amp;".log") then
      logCommand = 8
  Else
      logCommand = 2
      Set objLogProgram = obj.CreateTextFile("C:\mcgfiles\logs\program\program_"&amp;hostname&amp;"_"&amp;datestamp&amp;".log")
      objLogProgram.Close
  End If
  
  Set objLogActivity = obj.OpenTextFile("C:\mcgfiles\logs\activity\activity_"&amp; hostname &amp;"_"&amp;datestamp&amp;".log",2)
  Set objLogStatus = obj.OpenTextFile("C:\mcgfiles\logs\status\status_"&amp; hostname &amp;"_"&amp;datestamp&amp;".log",2)
  Set objLogProgram = obj.OpenTextFile("C:\mcgfiles\logs\program\program_"&amp;hostname&amp;"_"&amp;datestamp&amp;".log",logCommand)
  
  Set objCurrHashFile = obj.OpenTextFile("C:\mcgfiles\avp\hash.txt",1)
  current_hash = objCurrHashFile.ReadLine
  objCurrHashFile.Close
  
  comparison = StrComp(new_hash, current_hash)
  If comparison = 0 Then
      objLogProgram.WriteLine datestamp2&amp;vbTab&amp;Wscript.ScriptName&amp;vbTab&amp;"INFO"&amp;vbTab&amp;"UPDATE STOPPED. AVP FILE IN LOCAL IS UPDATED."
      objLogProgram.Close
      objLogActivity.Write datestamp2&amp;vbTab&amp;Wscript.ScriptName&amp;vbTab&amp;"INFO"&amp;vbTab&amp;"AVP IN LOCAL IS CURRENTLY UPDATED."
      objLogActivity.Close
      objLogStatus.Write "8"&amp;vbTab&amp;datestamp2
      objLogStatus.Close
      updateAVP = False
  Else
      logfile = "c:\mcgfiles\logs\program\updateAVPSFTPLogs_"&amp;datestamp&amp;".log"
      commandfile = "c:\scripts\updateAVPSFTPCommands.txt"
      Set shellSFTP=createobject("wscript.shell")
      shellSFTP.run "cmd /k c:\scripts\psftp -i c:\scripts\rsa_id.ppk root@192.168.22.144 -be -b "&amp;commandfile&amp;" &gt;"&amp;logfile,0
      Set shellSFTP = Nothing
      updateAVP = True
  End If
  
  If updateAVP = True Then
      objLogProgram.WriteLine datestamp2&amp;vbTab&amp;Wscript.ScriptName&amp;vbTab&amp;"INFO"&amp;vbTab&amp;"OPENING SFTP FOR AVP FILE TRANSFER"
      objLogProgram.Close
      retryLocalSWF = 3
      Do While retryLocalSWF &gt; 0
          If obj.FileExists("C:\mcgfiles\avp-temp\local.swf") Then
              tokenGenHash = True 
              retryLocalSWF = retryLocalSWF - 3
          Else
              Wscript.Sleep 10000
              tokenGenHash = False
              retryLocalSWF = retryLocalSWF - 1           
          End If
      Loop
  End If
  If tokenGenHash = True Then
      objLogProgram.WriteLine datestamp2&amp;vbTab&amp;Wscript.ScriptName&amp;vbTab&amp;"SUCCESS"&amp;vbTab&amp;"AVP SUCCESSFULLY DOWNLOADED. GENERATING HASH FOR VALIDITY"
      objLogProgram.Close
      Set WshShell= Wscript.CreateObject("Wscript.Shell")
      WshShell.Run "C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe $someFilePath = 'C:\mcgfiles\avp-temp\local.swf';$md5 = new-object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider;$md5hash = [System.BitConverter]::ToString($md5.ComputeHash([System.IO.File]::ReadAllBytes($someFilePath)));$newmd5hash = $md5hash -replace '-','';$newmd5hash.ToLower() | Out-File 'C:\mcgfiles\avp-temp\hash.txt' -Encoding Default; return $newmd5hash.ToLower()",0
      retryHashTXT = 0
      Do While retryHashTXT &lt; 3
          If obj.FileExists("C:\mcgfiles\avp-temp\hash.txt") Then
              tokenReadHash = True
              retryHashTXT = retryHashTXT + 3
          Else
              Wscript.Sleep 10000
              tokenReadHash = False
              retryHashTXT = retryHashTXT + 1
          End If
      Loop        
  Else
      objLogProgram.WriteLine datestamp2&amp;vbTab&amp;Wscript.ScriptName&amp;vbTab&amp;"ERROR"&amp;vbTab&amp;"AVP WAS NOT TRANSFERRED PROPERLY."
      objLogProgram.Close
      objLogActivity.WriteLine datestamp2&amp;vbTab&amp;Wscript.ScriptName&amp;vbTab&amp;"ERROR"&amp;vbTab&amp;"AVP WAS NOT TRANSFERRED PROPERLY."
      objLogActivity.Close
      objLogStatus.Write "9"&amp;vbTab&amp;datestamp2
      objLogStatus.Close
  End If
  
  If tokenReadHash = True Then
      Set objDownHashFile = obj.OpenTextFile("C:\mcgfiles\avp-temp\hash.txt",1)
      downloaded_hash = objDownHashFile.ReadLine
      objDownHashFile.close
  
  End If
  </code></pre>
  
  <p>Thanks in advance</p>