Asked by:
VBS Script is not executing the batch file

General discussion
-
I have created a vbs script that schedules a task to execute a batch file daily.The task gets scheduled but the batch file does not gets executed
Function DeleteLogFiles
Dim sDomainUserName, sCommand, iReturn
On Error Resume Next
LogDetail("Start: Function DeleteLogFiles")
'sDomainUserName = "s-" & Mid(sComputerName, 3,4)
sCommand = "SchTasks.exe /delete /f /TN " & chr(34) & "DeleteLog" & chr(34)
LogDetail(sTab & "Deleting old DeleteLog task.")
iReturn = oWShell.Run(sCommand,7,True)
If iReturn <> 0 Then
LogDetail(sTab & "ERROR! An error " & iReturn & " occurred while deleting the old task.")
bCriticalErrors = True
End If
LogDetail(sTab & "This is a server, using s_GnightSrvr.ini")
sCommand = "SchTasks.exe /create /RU " & sScheduledTaskUser & " /RP " & sScheduledTaskPassword & " /SC Daily /TN " & chr(34) & "DeleteLog" & Chr(34) & " /TR " & chr(34) & "C:\winstore\apps\DeleteLog.bat" & Chr(34) & " /ST " & sNextDeleteTime & " /SD " & sNextDeleteDate
LogDetail(sTab & "Re-creating DeletLogFiles scheduled task.")
iReturn = oWShell.Run(sCommand,7,True)
If iReturn <> 0 Then
LogDetail(sTab & "ERROR! An error " & iReturn & " occurred while re-creating the new task.")
bCriticalErrors = True
End If
On Error goto 0
LogDetail("End: Function DeleteLogFiles")
End FunctionThis is the function of the vbs script
- Changed type Bill_Stewart Tuesday, May 8, 2018 6:24 PM
- Moved by Bill_Stewart Tuesday, May 8, 2018 6:24 PM This is not "scripts on demand"
Friday, March 9, 2018 4:54 AM
All replies
-
Hi everyone,
I need to wite a .vbs scirpt which will schedule a task to delete some files which are older than 3 days in a specific path.The script needs to run every saturday at 2:30am.
The command i will be using inside the scirpt is
forfiles /P "C:\temp\" /S /D -3 /C "cmd /c del @path"
Can you help me to write a vbs scipt that will schedule a task which will run the above mentioned command every saturday at 2:30 am
- Merged by Bill_Stewart Friday, March 9, 2018 6:54 PM Duplicate
Wednesday, March 7, 2018 11:05 AM -
Read this first:
This forum is for scripting questions rather than script requests
-- Bill Stewart [Bill_Stewart]
Wednesday, March 7, 2018 3:52 PM -
Use SCHTASKS
SCHTASKS /?
Post in Windows General forum for help with this utility.
\_(ツ)_/
Wednesday, March 7, 2018 5:20 PM -
Can you tell me which forum can be useful for meThursday, March 8, 2018 5:36 AM
-
Can you tell me which forum can be useful for me
Use a search engine.
-- Bill Stewart [Bill_Stewart]
Thursday, March 8, 2018 3:18 PM -
First remove the "On Error" line.
If you don't handle errors then don't ignore them
Where did you find this script.
Why do you need a VBS script to create one task?
What batch file are you referring to?
Can you please format you code so it is readable and post using the code posting tool.
\_(ツ)_/
Friday, March 9, 2018 5:11 AM -
Hi i am writing a VBS cript to schdule a task which will delete log files from a specific location i am using error handle and getting error 76 which i think is path not found error
sCommand = "SchTasks.exe /create /RU " & sScheduledTaskUser & " /RP " & sScheduledTaskPassword & " /SC Daily /TN " & chr(34) & "DeleteLog" & Chr(34) & " /TR " & chr(128) & "forfiles /P ""C:\winstore\logs"" /S /C ""cmd /c del @path""" & Chr(34) & " /ST " & sNextDeleteTime & " /SD " & sNextDeleteDate
The command for deleting files is forfiles /P "C:\winstore\logs" /S /C "cmd /c del @path"
Can someone please help
- Merged by Bill_Stewart Friday, March 9, 2018 3:44 PM Duplicate
Friday, March 9, 2018 6:45 AM -
Friday, March 9, 2018 7:39 AM