Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    5 Star Lounger
    Join Date
    Jul 2001
    Location
    Terneuzen, Netherlands
    Posts
    895
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Execute script in Task Scheduler (XP)

    I'd like to run a (Win32) command-line program (actually RoboCopy) on certain times.

    To do that, I'd like to create a (VBS?) script that sets-up task scheduler automatically. How do I set this up? The user is always the same and always logged-on.

    If at all possible I'd like to see if I can reduce the process priority of the RoboCopy task to just a little below normal to avoid to much interference with running processes.

    Any ideas on if and how I could tackle this one?

    Erik Jan

  2. #2
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Execute script in Task Scheduler (XP)

    Congratulations on choosing RoboCopy!

    How many times per day do you want to run this copy? If only a few, it might be easiest just to set up a number of copy jobs which differ only in the date. Depending on the complexity of the ROBOCOPY, you will either be wanting to run ROBOCOPY itself, or a BATch file which contains the ROBOCOPY command and assorted other stuff.

    For examples, this is what I schedule to run once a day, to copy all changed files on C: to my external hard disk on E:
    <pre>@echo off
    cls
    echo +----------+
    echo I CopyCtoE I ROBOCOPY all new/changed directories and files from C: to E:
    echo +----------+ and delete from E: all newly-deleted files from C:

    :: check that we have the correct source disk

    dir c: | find "JohnGray_C" > nul
    if errorlevel 1 echo %~n0 Wrong source volume & goto :eof

    :: check that we have the correct target disk

    dir e: | find "MaxtorExt_E" > nul
    if errorlevel 1 echo %~n0 Wrong target volume & goto :eof

    setlocal

    :: generalised DATE and TIME routine for NT4/W2K/WXP and all Regional Settings
    :: %yy% will contain four digits, 20nn;
    :: %mm%, %dd% and time variables %hr%, %mn%, %sc% and %th% contain two digits
    if "%date%A" LSS "A" (set toks=1-3) else (set toks=2-4)
    for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo.^|date') do (
    for /f "tokens=%toks% delims=.-/ " %%e in ('date /t') do (
    for /f "tokens=5-8 delims=:., " %%i in ('echo.^|time') do (
    (set %%a=%%e) & (set %%b=%%f) & (set %%c=%%g) & rem create yy, mm, dd
    (set hr=%%i) & (set mn=%%j) & (set sc=%%k) & (set th=%%l)
    rem note the variable names for Time: hr, mn, sc, th
    )))
    if 1%yy% LSS 200 (set yy=20%yy%) & :: ensure 4-digit years in %yy%
    if 1%hr% LSS 20 (set hr=0%hr%) & :: ensure 2-digit hours in %hr%

    set source=C:
    set target="E:RoboCopy of C drive"
    if not exist E:RoboLogs*.* MD E:RoboLogs

    set log=E:RoboLogsRBC_%yy%%mm%%dd%_%hr%%mn%.log
    set opts=/mir /np /r:0 /w:2

    :: log to console if there is a passed parameter
    if /i "%1"=="Y" echo %~n0: ROBOCOPYing %source% to %target%...
    if /i "%1"=="Y" echo %~n0: logging to %log%...
    set start=%time%
    if /i "%1"=="Y" echo %~n0: Started at %start%

    robocopy %source% %target% %opts% > %log%

    set ended=%time%
    echo/ >> %log%
    echo/ >> %log%
    echo Started at %start% >> %log%
    echo Ended at %ended% >> %log%
    echo Errorlevel %errorlevel% from ROBOCOPY >> %log%

    :: bypass the log to console if there is no passed parameter
    if .%1==. endlocal & goto :eof
    echo %~n0: Ended at %ended%
    ping -n 11 127.0.0.1 > nul

    endlocal</pre>


    John
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

  3. #3
    5 Star Lounger
    Join Date
    Jul 2001
    Location
    Terneuzen, Netherlands
    Posts
    895
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Execute script in Task Scheduler (XP)

    Thanks for the feedback John, great batch-file!

    My batch file is simple (and done) however; it needs to be executed only once/day. As said, I'd be looking for two things

    1. How can I set-up the task

    i.s.o. doing that manually, I thought of having a script that would copy the files -like Robocopy.exe etc.- to the HD and that would set-up the task-scheduler automatically. Now the copying part, I've done before using a small VBS script; 'programming' the task-scheduler would be new to me


    2. Can I make RoboCopy run at lower priority.

    Personally, I thought this cannot be done when I call RoboCopy from a BAT-file; in stead I think this should be converted to VBS too in order to control that. My bat-file is basically just the call to RoboCopy, so that shouldn't have to be a big deal. Still I don't know how to tackle this too


    Appreciate further help ;-)

    Erik Jan

  4. #4
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Execute script in Task Scheduler (XP)

    Personally, not knowing VBS, I would just do Start -> Control Panel -> Scheduled Tasks and click on Add Scheduled Tasks. A wizard walks you though (some of) the options, and once completed you can double-click on the newly named job and check through the four tabs. I can't see any about altering the priority, though, but since file copy tasks are not CPU-intensive, I wouldn't even bother with thinking about it! There may be slight snags about what you put in the RunAs box, but first things first...

    Perhaps consider this as a New Learning Experience?

    John
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

  5. #5
    5 Star Lounger
    Join Date
    Jul 2001
    Location
    Terneuzen, Netherlands
    Posts
    895
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Execute script in Task Scheduler (XP)

    Thanks,

    But I'll have to repeat this for 50+ systems (...) that's why I was looking to automate the install.

    Wrt priority of the task; I agree that copying might not be CPU intensive; on the other hand, the systems are involved in real-time data-acquisistion AND the #files to be copied might run in the hundreds each day...

    See my point(s) ;-)

  6. #6
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Execute script in Task Scheduler (XP)

    <UL><LI>Set up the task on one machine, and check that it works as scheduled.<LI>Look for the resulting .JOB file in C:WINDOWSTasks (you may find difficulty with this, since Windows Explorer doesn't want to display the file in the expected way!).<LI>Copy the file to the corresponding directory in a second machine<LI>Check that it works as scheduled there, too<LI>If it does, copy it everywhere else...[/list]Here's the top and bottom of today's log from my ROBOCOPY job previously described......
    <pre>-------------------------------------------------------------------------------
    ROBOCOPY :: Robust File Copy for Windows :: Version XP010
    -------------------------------------------------------------------------------

    Started : Tue Oct 11 09:25:25 2005

    Source : C:
    Dest : E:RoboCopy of C drive

    Files : *.*

    Options : *.* /S /E /COPYAT /PURGE /MIR /NP /R:0 /W:2

    ------------------------------------------------------------------------------
    <LOTS of STUFF about individual files omitted>
    ------------------------------------------------------------------------------

    Total Copied Skipped Mismatch FAILED Extras
    Dirs : 5812 7 5805 0 0 3
    Files : 105039 1209 103795 0 35 478
    Bytes : 19.592 g 391.91 m 18.670 g 0 552.22 m 19.01 m
    Times : 0:02:06 0:00:51 0:00:00 0:01:14

    Speed : 7922511 Bytes/sec.
    Speed : 453.329 MegaBytes/min.

    Ended : Tue Oct 11 09:27:32 2005


    Started at 9:25:25.50
    Ended at 9:27:32.56
    Errorlevel 11 from ROBOCOPY </pre>


    John
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

  7. #7
    5 Star Lounger
    Join Date
    Jul 2001
    Location
    Terneuzen, Netherlands
    Posts
    895
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Execute script in Task Scheduler (XP)

    Thanks,

    That is something I'll try...

    Leaves me with the priority problem... I thought / hoped that this could be done through starting RoboCopy NOT via a BAT-file but through a (VBS) script...

    Anyone?

  8. #8
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Execute script in Task Scheduler (XP)

    Try something like:
    <code>
    Const NORMAL = 32
    Const LOW = 64
    Const HIGH = 128
    Const BELOW_NORMAL = 16384
    Const ABOVE_NORMAL = 32768

    Dim strExecutable, intPriority, intProcessID

    strExecutable = "C:Windowsnotepad.exe"
    intPriority = BELOW_NORMAL


    Set objWMIService = GetObject("winmgmts:{impersonationLevel=" & _
    "impersonate}!.rootcimv2")
    Set objStartup = objWMIService.Get("Win32_ProcessStartup")
    Set objConfig = objStartup.SpawnInstance_
    objConfig.PriorityClass = intPriority
    Set objProcess = GetObject("winmgmts:rootcimv2:Win32_Process")
    objProcess.Create strExecutable, Null, objConfig, intProcessID
    </code>

    note: you will obviously need to fill in the correct path to the Robocopy program.
    HTH.
    Regards,
    Rory

    Microsoft MVP - Excel

  9. #9
    5 Star Lounger
    Join Date
    Jul 2001
    Location
    Terneuzen, Netherlands
    Posts
    895
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Execute script in Task Scheduler (XP)

    Looks pretty cool <img src=/S/cool.gif border=0 alt=cool width=15 height=15>

    I'll try tomorrow, thanks.

  10. #10
    5 Star Lounger
    Join Date
    Jul 2001
    Location
    Terneuzen, Netherlands
    Posts
    895
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Execute script in Task Scheduler (XP)

    Still not working... (I think; no log is created and I KNOW files should have to be copied); this is what I have:

    Const NORMAL = 32
    Const LOW = 64
    Const HIGH = 128
    Const BELOW_NORMAL = 16384
    Const ABOVE_NORMAL = 32768

    Dim strExecutable, intPriority, intProcessID

    strExecutable = "D:MyPath which is a bit long actuallyrobocopy.exe""cirTargetDir"" ""cestDir"" /s /b /copyall /log:RoboCopy.log /njh /ndl /nfl /nc /ns /np /TEE"

    ' Append /L to test only

    intPriority = BELOW_NORMAL

    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonat e}!.rootcimv2")
    Set objStartup = objWMIService.Get("Win32_ProcessStartup")
    Set objConfig = objStartup.SpawnInstance_
    objConfig.PriorityClass = intPriority
    Set objProcess = GetObject("winmgmts:rootcimv2:Win32_Process")
    objProcess.Create strExecutable, Null, objConfig, intProcessID

  11. #11
    5 Star Lounger
    Join Date
    Jul 2001
    Location
    Terneuzen, Netherlands
    Posts
    895
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Execute script in Task Scheduler (XP)

    My target & dest dirs have spaces, the lost space was a typo (by me when changing the names of directories in generic ones). So... with the space it still doesn't work

  12. #12
    5 Star Lounger
    Join Date
    Jul 2001
    Location
    Terneuzen, Netherlands
    Posts
    895
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Execute script in Task Scheduler (XP)

    Finally found that the logfile was somewhere else... it's content may reveal something. I need some more time but will let you know how this ended...

  13. #13
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Execute script in Task Scheduler (XP)

    OK, let me know if it doesn't work and I'll see if I can get a trial copy of Robocopy to test against (I've never had to use this with that many arguments and switches, though in theory it shouldn't make a difference.)
    Regards,
    Rory

    Microsoft MVP - Excel

  14. #14
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Execute script in Task Scheduler (XP)

    Try:
    <code>strExecutable = "D:MyPath which is a bit long actuallyrobocopy.exe ""cirTargetDir"" ""cestDir"" /s /b /copyall /log:RoboCopy.log /njh /ndl /nfl /nc /ns /np /TEE"</code> (note space after .exe)
    or, if your source and desination directory paths do not have spaces, just:
    <code>strExecutable = "D:MyPath which is a bit long actuallyrobocopy.exe cirTargetDir cestDir /s /b /copyall /log:RoboCopy.log /njh /ndl /nfl /nc /ns /np /TEE"</code>

    If that doesn't work, double check your syntax by running that directly from a command prompt.
    Regards,
    Rory

    Microsoft MVP - Excel

  15. #15
    5 Star Lounger
    Join Date
    Jul 2001
    Location
    Terneuzen, Netherlands
    Posts
    895
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Execute script in Task Scheduler (XP)

    OK, things are working and I'm almost there (as promised; I'll make the final version available here).

    Let me already share some light on what has been going on... and pose yet some new questions...

    * It appears (and this is probably logical); that in all path/file parts, no spaces should be present or the call would mess-up. So I've chosen to enclose all in " 's

    * When one runs RoboCopy as a script; it appears that this task is not having the same authorization that one has as a user (e.g. when running as a BAT-file).
    When I finally found my logfiles back, I noticed that my /COPYALL option didn't work as "You do not have the Manage Auditing user right".
    Also, the "Backup and Restore files user rights" suddenly had gone.
    These two made me drop the /COPYALL and the /B options

    * I found out that a default log-file path could be c:windowssystem32 (don't know why; that's NOT where my RoboCopy program is)
    Doesn't matter; I now specify the location of the log-file to be the same directory as the VBS script

    Questions:

    * Can I run the VBS as me (the currently logged on user), in stead of as default user

    * Can I, in VB-script, put a message on the screen AND take that away without user interaction...??? I was thinking about generating a message saying: "Copying in progress..." and then automatically replace that by "Done" for e.g. 10 seconds (counting down??)

    Any more wizards out there?

    Thanks,

    Erik Jan

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •