'Script that takes Admin defined time intervals as command line 'parameters, creates scheduled task with this information, and 'returns/outputs the defined time windows 'Put into place: 03/27/2014 'TWO command line variables are REQUIRED for use 'Note: Times must be defined in format: 00:00:00 'Example Command Line Input: 19:00:00 22:00:00 'Examples of Time input: 08:15:00 (8:15a), 13:15:00 (1:15p) Dim objShell,arg0,arg1,StrtTsk,StpTsk,StrtTsk2,StpTsk2 'Admin defined Time to Start Maintenance Window arg0 = WScript.Arguments.Item(0) 'Admin defined Time to Stop Maintenance Window arg1 = WScript.Arguments.Item(1) 'Check Operating System details and create Scheduled Tasks based on findings 'Set fso = CreateObject("Scripting.FileSystemObject") Set objShell = WScript.CreateObject ("WScript.shell") if objShell.ExpandEnvironmentStrings("%PROGRAMFILES(x86)%")="%PROGRAMFILES(x86)%" then path = objShell.ExpandEnvironmentStrings("%PROGRAMFILES%") path2 = Left(path, Len(path) - 13) path3 = path2 & "Progra~1\" else path = objShell.ExpandEnvironmentStrings("%PROGRAMFILES(x86)%") path2 = Left(path, Len(path) - 19) path3 = path2 & "Progra~2\" end if 'Check to see if stop time crosses over midnight and if so, add a day if arg1 < arg0 then startdt = Right("0" & DatePart("m",Date()), 2) & "/" & Right("0" & DatePart("d",Date()), 2) & "/" & DatePart("yyyy",Date()) stopdt = Right("0" & DatePart("m",DateAdd("d",1,Date())), 2) & "/" & Right("0" & DatePart("d",DateAdd("d",1,Date())), 2) & "/" & DatePart("yyyy",DateAdd("d",1,Date())) else startdt = Right("0" & DatePart("m",Date()), 2) & "/" & Right("0" & DatePart("d",Date()), 2) & "/" & DatePart("yyyy",Date()) stopdt = Right("0" & DatePart("m",Date()), 2) & "/" & Right("0" & DatePart("d",Date()), 2) & "/" & DatePart("yyyy",Date()) end if 'Output/Return Start and Stop Times defined by Admin wscript.echo ("Start and Stop Times of Maintenance Window listed respectively below:" & vbCrLf & startdt & " at " & arg0 & vbCrLf & stopdt & " at " & arg1 & vbCrLf) 'Scheduled Task Naming and variables StrtTsk = "schtasks /create /f /tn ""GFI MAX, Start Maintenance Window"" /ru System /tr " & """" &path3 & "Advanc~1\winagent.exe /offline" & """" & " /sc once /sd " & startdt & " /st " & arg0 StpTsk = "schtasks /create /f /tn ""GFI MAX, Stop Maintenance Window"" /ru System /tr " & """" &path3 & "Advanc~1\winagent.exe /online" & """"& " /sc once /sd " & stopdt & " /st " & arg1 'Start Task Scheduler Service before creating Scheduled Tasks objShell.run "net start ""task scheduler"" /y" objShell.run (StrtTsk) objShell.run (StpTsk)