Hi
This thread is a pick-up of a long and old thread I started a few years back, and since then, I re-worked the script, and have a little problem with it.
For reference here is the old thread
thread329-1215138
For a brief note, this is what the script does:
Checks for the username's first letter, and based on that it decides which day the user should do the backup. If its not the given day, it stops.
Then it checks for a Registry key, and checks when the last backup was carried out. If its on the same day, the script exits, as we dont want two backups on the same day.
Once that is done, it has 3 folders to back up from. Since not all users have the same folders, it checks if there is the folder existing in the first place, and if the folder exists, then it checks if there are any pst files inside. If all that passes, then it carries out the backup.
The only problem I have with the script is that If the folder doesnt exist, it will fail somehow. As I am not even close being a pro, actually not even a beginner at scripting, I dont know where I should start looking.
The following works:
There is a folder, but it has no PST file in it.
The following doesnt work:
There is no folder.
It used to work, when I didnt check for the file being there, and by working that out, I somehow broke the other function to check if the folder is there.
My feeling is that in the beginning, it checks for the folder, but once it finds out it not being there, it wont skip automatically to the next folder. It rather goes on, looks for the file, etc etc.
Any suggestions are welcome,
Main contribution in the old thread came from mrmovie and markdmac, thanks both of you. I took a little piece of the code from Skie, again thanks.
This is how the code looks at the moment,
Ben
This thread is a pick-up of a long and old thread I started a few years back, and since then, I re-worked the script, and have a little problem with it.
For reference here is the old thread
thread329-1215138
For a brief note, this is what the script does:
Checks for the username's first letter, and based on that it decides which day the user should do the backup. If its not the given day, it stops.
Then it checks for a Registry key, and checks when the last backup was carried out. If its on the same day, the script exits, as we dont want two backups on the same day.
Once that is done, it has 3 folders to back up from. Since not all users have the same folders, it checks if there is the folder existing in the first place, and if the folder exists, then it checks if there are any pst files inside. If all that passes, then it carries out the backup.
The only problem I have with the script is that If the folder doesnt exist, it will fail somehow. As I am not even close being a pro, actually not even a beginner at scripting, I dont know where I should start looking.
The following works:
There is a folder, but it has no PST file in it.
The following doesnt work:
There is no folder.
It used to work, when I didnt check for the file being there, and by working that out, I somehow broke the other function to check if the folder is there.
My feeling is that in the beginning, it checks for the folder, but once it finds out it not being there, it wont skip automatically to the next folder. It rather goes on, looks for the file, etc etc.
Any suggestions are welcome,
Main contribution in the old thread came from mrmovie and markdmac, thanks both of you. I took a little piece of the code from Skie, again thanks.
This is how the code looks at the moment,
Ben
Code:
Set WshShell = CreateObject("Wscript.Shell")
varUserName = WshShell.ExpandEnvironmentStrings("%username%")
'Set the Dates of the week the backup occures
strDay = 2 'default for unknown configured user
'usernames starting with a given letter will conduct the backup on the given day
'Sunday =1 Saturday =7
Select Case Left(varUserName,1)
Case "a","b","c","d","e"
strDay = 2
Case "f","g","h","i","j"
strDay = 3
Case "k","l","m","n","o"
strDay = 4
Case "p","q","r","s","t"
strDay = 5
Case "u","v","w","x","y","z"
strDay = 6
End Select
'Check if today is the day we need to run the Backup (checks Registry for recent backup, and username for 1st character)
If CStr(strDay) = CStr(Weekday(Now())) Then
Set WshShell = CreateObject("Wscript.Shell")
On Error Resume Next
'Reads key from registry to see if we have already backed up today
strTemp = WshShell.RegRead("HKLM\Software\MYCOMPANY\PSTCopyFlag")
On Error Goto 0
If CStr(strTemp) <> CStr(Date) Then
'If we do the backup today, pop up a warning message to the user
WshShell.Popup "Your emails are being backed up now. You may safely leave the machine, it will proceed automatically", 5
Set objFSO = CreateObject("Scripting.FileSystemObject")
strUserName = WshShell.ExpandEnvironmentStrings("%username%")
Set fso = createobject("Scripting.FileSystemObject")
If objFSO.FolderExists("D:\Mail") Then Set oFolder = fso.GetFolder("D:\Mail")
pstCount = 0
For Each oFile In oFolder.files
If (Lcase(Right(oFile.Name,3))) = "pst" Then
pstCount = pstCount + 1
End If
Next
If pstCount <> 0 Then objFSO.CopyFile "D:\Mail\*.pst" , "\\backupserver\PST\" & strUserName & "\"
If objFSO.FolderExists("C:\Mail") Then Set oFolder = fso.GetFolder("C:\Mail")
pstCount = 0
For Each oFile In oFolder.files
If (Lcase(Right(oFile.Name,3))) = "pst" Then
pstCount = pstCount + 1
End If
Next
If pstCount <> 0 Then objFSO.CopyFile "C:\Mail\*.pst" , "\\backupserver\PST\" & strUserName & "\"
If objFSO.FolderExists("C:\Documents and Settings\" & strUserName & "\Local Settings\Application Data\Microsoft\Outlook") Then Set oFolder = fso.GetFolder("C:\Documents and Settings\" & strUserName & "\Local Settings\Application Data\Microsoft\Outlook")
pstCount = 0
For Each oFile In oFolder.files
If (Lcase(Right(oFile.Name,3))) = "pst" Then
pstCount = pstCount + 1
End If
Next
If pstCount <> 0 Then objFSO.CopyFile "C:\Documents and Settings\" & strUserName & "\Local Settings\Application Data\Microsoft\Outlook\*.pst" , "\\backupserver\PST\" & strUserName & "\"
Set objFSO = Nothing
'set the FLAG
WshShell.RegWrite "HKLM\Software\MYCOMPANY\PSTCopyFlag", Date
End If
End If