• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

Issue with a vb script and scheduled task

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

pik4chu

Senior Yellow Forum Rat
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:

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.
 
It may not have anything to do with your script. You need to check the properties of your scheduled task. Make sure that it is set to run even when no user is logged in (looks like this is set) and you need to set a username and password for it to use when running.
 
This might be overkill, but it may help you get some logging going so you can narrow down where the script is failing. Is this a Windows Vista, 2008, or 7 system? If it is, you may want to experiment with turning UAC off long enough to see if the script works. If it works with that disabled, you will need to check in the security policy for things like "Act as part of the operating system" and "allow account to impersonate another user", though, I am going from memory on those settings...
 
its running in server 2003 R2, 32bit.
Scheduled task is currently set to run under an account with enterprise admin priveleges.
 
I notice you are calling 7zip without the full path. Have you tried putting the full path into the zipper procedure in case the path information is not right for the scheduled task? If it's in the same folder as the script, did you set the working directory?
 
the script and and all the files needed to be run are in the same folder. I didnt set a working directory but it ran fine without it, guess I can try that though.

*edit* checked it and the working directory for 7zip is simply where it puts the temp archives whiles its creating them. This is by default the same folder it resides in which is fine where it is so I dont need to set that.
 
rewriting this script almost entirely now to add in logging and since I found the right way to generate file names. It still runs manually though, havent yet tested it as scheduled.
 
The script seems to be running now. Though it did miss a day of running and I have no idea why but for the most part when/if it fails it seems to be during the file copy, the rest of the script works fine.
 
Back