Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Backup PST script won’t copy from standard outlook folder

Status
Not open for further replies.

kanga121

IS-IT--Management
Apr 2, 2008
14
Hey all… needing a little help… I have just started creating a script to back up .PST files to a central location. I’m going to start simple and build it up to do all that I need. But I can’t even get past the copy location, if I use;

objFSO.CopyFile "C:\Documents and Settings\" & varUserName & "\Local Settings\Application Data\Microsoft\Outlook\*.pst"

It won’t copy the file, even if I use the user name explicitly. Still wont copy. However if I copy it from another location say “C:\PSTtest” works fine

Does anyone know why that would be?
 
Here you have no destination specified at all, it sure won't work in any case.

This is a recap of the line I posted to the related thread to avoid all confusion.
[tt]
objFSO.CopyFile "C:\Documents and Settings\" & varUserName & "\Local Settings\Application Data\Microsoft\Outlook\*.pst" , [red]"\\sql1\Backups\PST\" & varUserName & "\", true[/red]
[/tt]
 
Hey, thanks... i did but the "to" path...


ON Error Resume Next

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile "C:\Documents and Settings\" & varUserName & "\Local Settings\Application Data\Microsoft\Outlook\*.pst" , "\\sql1\Backups\PST\shanet"


that's why i say that it will work when i use another path (say “C:\PSTtest”) but it wont work to the outlook folder... and i'm wondering why??
 
I don't have things to add apart from those trial existence, permission etc etc... that you have to make sure yourself. Other than that read carefully the line (including comma and slash) - sometimes I am not sure of that, maybe not in your case.
 
What happens if you comment out the On Error Resume Next instruction ?

You may try this:
objFSO.CopyFile "C:\Documents and Settings\" & varUserName & "\Local Settings\Application Data\Microsoft\Outlook\*.pst" , "\\sql1\Backups\PST\shanet\", True

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV... that seems to have worked... well as long as I don’t use the \" & varUserName & "\

If I explicitly specify my username work fine… but I need to it to be username agnostic.

Any ideas??

Thanks, everyone’s as awesome help round here?
 
Forgot to add. Using " & varUserName & " I get an error “path not found”

Is there anything else I can use?

Thanks guys
 
I got it... I was missing this


Set WshShell = CreateObject("Wscript.Shell")
varUserName = WshShell.ExpandEnvironmentStrings("%username%")
 
Hey PHV… I tried your script as

Set WshShell = CreateObject("Wscript.Shell")
varUserName = WshShell.ExpandEnvironmentStrings("%username%")

If CStr(strDay) = CStr(Weekday(Now())) Then
'Reads key from registry to see if we have already backed up today
strTemp = WshShell.RegRead("HKLM\Software\MYCOMPANY\PSTCopyFlag")
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")
objFSO.CopyFile "C:\Documents and Settings\" & varUserName & "\Local Settings\Application Data\Microsoft\Outlook\*.pst" , "\\sql1\Backups\PST\" & varUserName & "\", True

Set objFSO = Nothing
'set the FLAG
WshShell.RegWrite "HKLM\Software\MYCOMPANY\PSTCopyFlag", Date
End If
End If


And it didn’t work

Any ideas where I’m going wrong??
 
And it didn’t work
Any chance you could post a little more info like, say, the error message(s) and the relevant line(s) of code ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Anyway, I'd replace this:
objFSO.CopyFile "C:\Documents and Settings\" & varUserName & "\Local Settings\Application Data\Microsoft\Outlook\*.pst" , "\\sql1\Backups\PST\" & varUserName & "\", True

with this:
strDest = "\\sql1\Backups\PST\" & varUserName
If Not objFSO.FolderExists(strDest) Then
objFSO.CreateFolder strDest
End If
objFSO.CopyFile "C:\Documents and Settings\" & varUserName & "\Local Settings\Application Data\Microsoft\Outlook\*.pst" , strDest & "\", True

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks for all your help mate, it’s very much appreciated… yeah this still didn’t work

Does this look right to you??




Set WshShell = CreateObject("Wscript.Shell")
varUserName = WshShell.ExpandEnvironmentStrings("%username%")

If CStr(strDay) = CStr(Weekday(Now())) Then
'Reads key from registry to see if we have already backed up today
strTemp = WshShell.RegRead("HKLM\Software\MYCOMPANY\PSTCopyFlag")
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")
strDest = "\\sql1\Backups\PST\" & varUserName
If Not objFSO.FolderExists(strDest) Then
objFSO.CreateFolder strDest
End If
objFSO.CopyFile "C:\Documents and Settings\" & varUserName & "\Local Settings\Application Data\Microsoft\Outlook\*.pst" , strDest & "\", True

Set objFSO = Nothing
'set the FLAG
WshShell.RegWrite "HKLM\Software\MYCOMPANY\PSTCopyFlag", Date
End If
End If
 
still didn’t work
What happens ? Error message ? Unexpected behaviour ? Computer crash ? ... ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Yeah sorry, should have said.

Nothing happens now, no error, no transfer... nothing @ all

Literally nothing happens.
 
Check the content of variables like strDay and strTemp.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Ok so strDest was wrong

strDest = "\\sql1\Backups\PST\" & varUserName & "\"

Should look like that.

But I’m not sure what you mean by check the content of strTemp?

Should it already have an entry in the registry? Because that’s something I don’t want to have to do… walk around to everyone’s machine and add that reg key.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top