none
BackupOutlook script failing and I do not understand it. RRS feed

  • Question

  • G'Day Everyone,

    Greetings.

    Can you help me with some pointers? I am new to scripting.

    This script complains about Line 86 Char 5 Error: Bad file name or number Code: 800A0034.

    '===================================================================
    'Description: VBS script to backup your pst-files.
    '
    'Comment: Before executing the vbs-file, set the amount of pst-files
    '         that you want to back up, the paths of the pst-files and
    '         the backup location (this can also be a network path).
    '         See the URL below for more configuration instructions and
    '         how to create a Scheduled Task for it.
    '
    ' author : Robert Sparnaaij
    ' version: 1.0
    ' website: http://www.howto-outlook.com/downloads/backupscript.htm
    '===================================================================

    '===================BEGIN MODIFY====================================

    'Set the amount of pst-files you want to copy. Start counting at 0!
    ReDim pst(1)

    'Define the location of each pst-file to backup. Increase the counter!
    pst(0) = "D:\Documents\Outlook Files\outlook.pst"
    pst(1) = "D:\Documents\Outlook Files\archive.pst"

    'Define your backup location
    BackupPath = "E:\Backup\Outlook\"

    'Keep old backups? TRUE/FALSE
    KeepHistory = FALSE

    'Maximum time in milliseconds for Outlook to close on its own
    delay = 30000 'It is not recommended to set this below 8000

    'Start Outlook again afterwards? TRUE/FALSE
    start = TRUE

    '===================STOP MODIFY====================================

    'Close Outlook
    Call CloseOutlook(delay)

    'Outlook is closed, so we can start the backup
    Call BackupPST(pst, BackupPath, KeepHistory)

    'Open Outlook again when desired.
    If start = TRUE Then
      Call OpenOutlook()
    End If


    Sub CloseOutlook(delay)
      strComputer = "."
      Set objWMIService = GetObject("winmgmts:" _
      & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

      'If Outlook is running, let it quit on its own.
      For Each Process in objWMIService.InstancesOf("Win32_Process")
        If StrComp(Process.Name,"OUTLOOK.EXE",vbTextCompare) = 0 Then
          Set objOutlook = CreateObject("Outlook.Application")
          objOutlook.Quit
          WScript.Sleep delay
          Exit For
        End If
      Next

      'Make sure Outlook is closed and otherwise force it.
      Set colProcessList = objWMIService.ExecQuery _
      ("Select * from Win32_Process Where Name = 'Outlook.exe'")
      For Each objProcess in colProcessList
        objProcess.Terminate()
      Next
      Set objWMIService = Nothing
      Set objOutlook = Nothing
      set colProcessList = Nothing
    End Sub


    Sub BackupPST(pst, BackupPath, KeepHistory)
      Set fso = CreateObject("Scripting.FileSystemObject")

      If KeepHistory = True Then
        ArchiveFolder = Year(Now) & "-" & Month(Now) & "-" & Day(Now)
        BackupPath = BackupPath & ArchiveFolder & "\"
      End If

      If fso.FolderExists(BackupPath) = False Then
        fso.CreateFolder BackupPath
      End If

      For Each pstPath in pst
        If fso.FileExists(pstPath) Then
          fso.CopyFile pstPath, BackupPath, True
        End If
      Next
      Set fso = Nothing
    End Sub


    Sub OpenOutlook()
      Set objShell = CreateObject("WScript.Shell")
      objShell.Run "Outlook.exe"
    End Sub

    • Moved by Bill_Stewart Wednesday, September 4, 2019 7:55 PM This is not "fix/debug/rewrite script for me" forum
    Saturday, April 6, 2019 10:20 AM

All replies

  • Please ask the author of the script to fix this for you.  We do not fix scripts that you have found on the Internet.


    \_(ツ)_/

    Saturday, April 6, 2019 5:23 PM
  • 'Comment: Before executing the vbs-file, set the amount of pst-files

    ' that you want to back up, the paths of the pst-files and

    ' the backup location (this can also be a network path).

    Did you follow the instructions?

    This script complains about Line 86 Char 5 Error: Bad file name

    Look at the code and see what's on line 86. In notepad click on the view menu and select Status Bar. That will show you line numbers.  What file name does it reference? Does it exist?  

    Saturday, April 6, 2019 8:48 PM
  • Thanks very much for the pointers.

    I will check into it.

    Saturday, April 6, 2019 10:40 PM