Hi everyone, I'm new to this forum and new to VBS script writing.
I searched through the threads on here regarding how to create a script to backup files and some great examples and tips and have attempted to write a script but do need some help tweaking it to make it fully functional.
What I am trying to do is:
NEED HELP - 1. Check to see if Outlook (version 2010) is open. If so then close outlook.
NEED HELP - 2. Back up the Outlook "archive.pst" file from a laptop C:\Users\current username\mail\archive.pst drive to a Microsoft server mapped drive Q:\current usernameCOMPLETED - 3. Give a prompt to the check if they want to backup the file.
COMPLETED - 4. Check if the archive file exists and if it does then prompt to overwrite.
COMPLETED - 5. Show progress of file being backed up and pop up a message window when completed.
I have completed #3-5 thanks to the tips I read on this forum. I'm able to back up the archive.pst file but I have to use my exact user name "bruce" in the filepath in the script instead of it automatically seeing who is currently logged in. So I need help to figure out how to:
A. On #1 above Close outlook if it is open. Possibly prompting the user to close it before continuing?
B. On #2 above Check and use the current username in the Cath and Q: path instead of using my specific "Bruce" name in the file path. That way anyone can use this script without having to modify it.
Here's my script so far:
' VBScript "Outback version 1" Project to copy the local outlook archive.pst file from the laptop C:\current user\mail to the mapped volume on the microsoft server Q:\current user' Written by Bruce33 on 2013-11-27
' &VbCr _ provides the carriage return and word wrap. Also I put 7 spaces on first message and 11 spaces on second message for centering
srcfile="C:\Users\Bruce\mail\archive.pst"
destdir="Q:\bruce\"
destfile=destdir & "\archive.pst"
Set Sh=WScript.CreateObject("WScript.Shell")
msg="Do you want to backup your Outlook archive file now?" & VbCr _
& VbCr _
& "Depending on file size this process can take up to 10 minutes to backup."
If Sh.Popup(msg,0,srcfile,33)<2 Then
Set fso=CreateObject("Scripting.FileSystemObject")
If fso.FileExists(destfile) Then
msg="Backup file already exists. Do you want to overwrite the file?"
If Sh.Popup(msg,0,destfile,33)>1 Then
WScript.Quit
End If
End If
Set SA=CreateObject("Shell.Application")
Set NS=SA.NameSpace(destdir)
NS.CopyHere srcfile,16
WScript.Echo "Backup completed! Have a Fantastic day!" & VbCr _
& VbCr _
& " Outback - v1 - written by Bruce33."
End If
I searched through the threads on here regarding how to create a script to backup files and some great examples and tips and have attempted to write a script but do need some help tweaking it to make it fully functional.
What I am trying to do is:
NEED HELP - 1. Check to see if Outlook (version 2010) is open. If so then close outlook.
NEED HELP - 2. Back up the Outlook "archive.pst" file from a laptop C:\Users\current username\mail\archive.pst drive to a Microsoft server mapped drive Q:\current usernameCOMPLETED - 3. Give a prompt to the check if they want to backup the file.
COMPLETED - 4. Check if the archive file exists and if it does then prompt to overwrite.
COMPLETED - 5. Show progress of file being backed up and pop up a message window when completed.
I have completed #3-5 thanks to the tips I read on this forum. I'm able to back up the archive.pst file but I have to use my exact user name "bruce" in the filepath in the script instead of it automatically seeing who is currently logged in. So I need help to figure out how to:
A. On #1 above Close outlook if it is open. Possibly prompting the user to close it before continuing?
B. On #2 above Check and use the current username in the Cath and Q: path instead of using my specific "Bruce" name in the file path. That way anyone can use this script without having to modify it.
Here's my script so far:
' VBScript "Outback version 1" Project to copy the local outlook archive.pst file from the laptop C:\current user\mail to the mapped volume on the microsoft server Q:\current user' Written by Bruce33 on 2013-11-27
' &VbCr _ provides the carriage return and word wrap. Also I put 7 spaces on first message and 11 spaces on second message for centering
srcfile="C:\Users\Bruce\mail\archive.pst"
destdir="Q:\bruce\"
destfile=destdir & "\archive.pst"
Set Sh=WScript.CreateObject("WScript.Shell")
msg="Do you want to backup your Outlook archive file now?" & VbCr _
& VbCr _
& "Depending on file size this process can take up to 10 minutes to backup."
If Sh.Popup(msg,0,srcfile,33)<2 Then
Set fso=CreateObject("Scripting.FileSystemObject")
If fso.FileExists(destfile) Then
msg="Backup file already exists. Do you want to overwrite the file?"
If Sh.Popup(msg,0,destfile,33)>1 Then
WScript.Quit
End If
End If
Set SA=CreateObject("Shell.Application")
Set NS=SA.NameSpace(destdir)
NS.CopyHere srcfile,16
WScript.Echo "Backup completed! Have a Fantastic day!" & VbCr _
& VbCr _
& " Outback - v1 - written by Bruce33."
End If