- Joined
- Jan 17, 2003
- Location
- Centennial, Colorado
So I created a vbscript to do varous tasks and copies and then set it to run as a scheduled task daily. The issue is that according to windows the task runs but according to everything else (ie, the files I need to change) nothing has happened. I do know the script works properly when run manually but it just wont do anything when scheduled. The other thing is I can tell it is not running because at the end of the script I added a command to create a windows event log entry (which also works on a manual run) but creates no entry when scheduled so I do know either its not running, or its not reaching the end.
I think what Im really looking for by posting in this section is some help with adding error handling/checking so I have something concrete to work with when troubleshooting (ie detailed logs).
Now I know how to simply insert commands to write to a file or a log but not how to do it with if/then type things so I can write different items if something fails etc. So that is the direct help I am looking for here. And it doesn't have to be windows event logs, simply appending to a text file is more than sufficient for this stage of testing.
Code is as follows:
and while I do know that mapping drives within scheduled tasks can be sketchy it doesn't even get to that part that I can see, the zip file part doesn't even run, no file is created, nada, it just does nothing but windows still thinks it runs.
I think what Im really looking for by posting in this section is some help with adding error handling/checking so I have something concrete to work with when troubleshooting (ie detailed logs).
Now I know how to simply insert commands to write to a file or a log but not how to do it with if/then type things so I can write different items if something fails etc. So that is the direct help I am looking for here. And it doesn't have to be windows event logs, simply appending to a text file is more than sufficient for this stage of testing.
Code is as follows:
Code:
Dim FSO, WSHShell, FName, ArcName
On Error Resume Next
'Variables for system objects and file names
Set WSHShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FilesystemObject")
FName = Year(Date) & "-0" & Month(Date) & "-" & Day(Date) & "-PM\"
ArcName = Year(Date) & "-0" & Month(Date) & "-" & Day(Date) & "-PM" & ".zip"
Call Zipper(FName, ArcName, WSHShell)
Wscript.Sleep 60000
Call Mover(ArcName, WSHShell, objFSO)
Sub Zipper(FName, ArcName, WSHShell) ' this sub runs the zip program
WSHShell.Run("7za.exe a Compressed\" & ArcName &" "& Fname)
End Sub
Sub Mover(ArcName, WSHShell, objFSO)
Dim ZipFile
Set ZipFile = objFSO.GetFile("Compressed\" & ArcName)
WSHShell.Run("net use H: \\255.255.255.255\$newserver /USER:**** ****")
objFSO.CopyFile ZipFile, "H:\", True
Set ZipFile = Nothing
WSHShell.Run("net use H: /delete")
WSHShell.Run("eventcreate /ID 999 /T INFORMATION /L APPLICATION /SO SQL_BK_Mover.vbs /D ""File compression and copy script has been run, please check local files to verify completion""")
End Sub
and while I do know that mapping drives within scheduled tasks can be sketchy it doesn't even get to that part that I can see, the zip file part doesn't even run, no file is created, nada, it just does nothing but windows still thinks it runs.