سؤال

I've written a simple autoupdater where I use a batch file with ftp commands to first download a "version" file, and compare the text to a local "version.txt" file - if the versions are different, I continue in the same batch script to download and install the update.

That part is fine, but when I create the task (using another batch file distributed in a setup.exe installer) since I need it to be run my hundreds of non-tech savvy users - I want to add a random time offset to the start time of the job, so that I don't have all terminals hitting my server for updates at exactly the same time.

SCHTASKS.EXE /CREATE /SC DAILY /ST 10:00 /TN "My Updater Task" /TR "c:\myupdater.bat"

I need this to be as compatible with XP as well as Vista+, but the majority user base would be XP. How can I put a different time like 10:05, 10:10, 10:00 etc. plus-minus 10 minutes to 10:00 so that I dont get hit by 200 clients simultaneously?

Also, is it possible to start the job without the command window showing? I've seen answers using vb script and cmdnow or some third party tool, which i'm not going to use for compatibility, virus scanner nuisance, and download requirements etc.

هل كانت مفيدة؟

المحلول

You could use %random% to generate your start time. There's a very useful forum discussion discussing how to do this in detail.

To run a batch file without the cmd window popping up try this (taken from here)

start /min myfile.bat

نصائح أخرى

I found this post on how to edit %random% to return a more acceptable number. it might be of help to you How to use random in BATCH script?.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top