I was trying to sync files from folder to another automatically,
I managed to do this using windows 10 task scheduler ,
I used a PowerShell code given by someone, then I run it every 5 min,
I wonder if there is any other way to make the task runs every time a file is added to the source folder to avoid running the task every 5 min.
yes there is. you can use the FileSystemWatcher. a sample script can be found in the technet gallery: https://gallery.technet.microsoft.com/scriptcenter/Powershell-FileSystemWatche-dfd7084b
Related
I have huge problem, and I don't know what heppend with my task in Task Scheduler in Windows 2012 R2
Task, has no working since few weeks, Same task in other server works fine.
When task run automatically it's not work, but in log I have information that is done without error, when I run same task manually (using Run on this task in TaskScheduler) then this work fine,
Where is the problem?
Someone can help me? Or suggest how to fix it or where looking the rootcasue of this problem?
Ok, I found where the problem was
When script it ran, file not exist in file directory, and that is the reason. When someone came to job at morning, and run the application file it created, and then manually run the task, task find the file.
SchTasks /Change /TN "cs2kconnect" /ST 06:00
I am getting Error the Parameter is Incorrect
The taskname is correct as I copied it directly, and when I put in a bad time it says /ST is Invalid.
I have managed to edit it other tasks using the same process, just this one does not want to change have tested this on multiple machines.
Any ideas?
This is running under windows 7
Though the question is very old but my answer below could be helpful to anybody still searching.
If you have made sure the name of the task and the parameter values are all correct and still face this error, then it is not because of the command you are running but because of the setup of the task.
You will face this error in 2 cases, first is when you create a Scheduled Task from the GUI and add a Trigger and not change the default Start Time. Second is when you add an Expire date and not change the default date that is set.
Task Scheduler - Trigger setup
The reason we get this error is becuase when you setup a trigger and not change its Start time or Expire time, the task scheduler creates it with milliseconds included, you can see that when you export the task to an XML. You will find that after you make any change to the start time and expire time (if it exists) and then export the to XML the milliseconds part is gone.
Task Scheduler - XML Export
To me it seems that when we run the "schtasks /change" command it validates the existing start time and expire time format before applying any change and it fails with this error which is definitely not very descriptive or accurate.
So, the solution is just make a small change to the times (you can change it back to original value) and then run the same command and it should work fine.
This error occurs only in Windows 7 / Windows Server 2008 R2 or earlier versions of OS.
The reason for this error is rather strange and may be is a bug in Windows which Microsoft fixed in later OS versions or in an Update which I could not find.
I have some really strange phenomena appearing on my PC, using Task Schedular.
We created a normal Task which is triggered every morning at 7 o'clock.
The interesting part is, that the history of Task Scheduler says, that it was running successfully.
But it didn't work.
I then created 2 other Scripts.
The first script is starting calc.
The second script creates a folder in c:/Temp
When starting those scripts over Explorer everything is running as expected.
But when running those scripts over task scheduler only the calc is starting and there won't be any folder in c:/Temp.
I already created a policy report, but nothing configured in the category Task Scheduler.
By the way the account configured in the Task Scheduler has local Admin right and run as batch job rights.
Thanks for your help.
Make sure to check any dependent files and permissions:
If permissions or ownership of a file changes that your task managed script depends on or uses (not necessary the one IN YOUR TASK), you need to make sure you re-sync your task to recognize those changes.
(for instance, if you've changed any permissions to C:\Temp but HAVEN'T resaved your Task...)
I've had the steps below fix issues when a script would run fine by itself, but after some change to it or a dependent file, would no longer run properly from Task Scheduler.
1) Open task schedular
2) find and double-click the troubled task like your going to edit it
3) Hit 'Ok'.
4) When prompted, enter credentials to save it. (If your credentials don't work then update them...that is a different problem)
5) try to re-run task from scheduler (r-click -> Run) then see if it works correctly.
NOTE: Just because the task successfully runs does NOT mean your script worked as it should. Check yourself to make sure the log file you want WAS created.
I'm running a simple/single vbscript in Windows Scheduler to perform 13 individual file exports from our SalesForce app. The script runs as expected. Depending upon network traffic, the 13 exports take 3-5 minutes total to complete.
My intent was to run these exports serially, but vbscript seems happy to run them in parallel. SalesForce accommodates with no issue or complaint.
Upon successful completion of the Export, I run a second vbscript to import these results into another application (via an msaccess function). This second vbscript also provides the desired result.
Question: Is there any way to programatically determine when the Export script has completed, to permit me to safely kick-off the Import script? Currently I have setup a 2nd Scheduler job to run the Import script 10 minutes after the separate Export script...but this could fail. I am looking to tie these two script more closely to one another.
Any suggestions?
Thanks!
There are a couple of options. If both scripts are running on the same system with the same permissions, you could have the first script actually kick off the second script whenever it's finished.
If the scripts require different permissions, or you need them to start from a task manager, have your first script start by looking for an existing file such as SCRIPT1.COMPLETE. If that file exists, have script1 delete the file and start processing. When script1 finishes it's processing, create that file. Then in script2, create a while loop that looks for SCRIPT1.COMPLETE. If the file is not there, hold off for a few seconds then try again. Don't exit the while loop until the complete file shows up. Have script2 delete the COMPLETE file when it finishes processing. I would recommend setting your "wait a while" function to at least 30 seconds or so, that way your script isn't just constantly checking.
I need to periodically distribute an updated set of files (DLL, javascript) as a patch release to multiple windows PCs of various versions (vista/XP/7 etc.). Currently I have a link on my website for each user to download the setup.exe file and manually install the patch (replaces the existing DLLs). In order to eliminate the manual process, I'm researching how to run a program automatically on windows (I assume that means a service) which will check my server periodically for an update, download it and automatically trigger the setup.exe (or some similar process to get the patch files replaced).
I'm not a windows developer per se, but have downloaded and tried to check various options (in order to not reinvent the wheel) such as Sparkle, DDay, CSAutoUpdater, Npackd and just started looking into Google Omaha - but most assume that check happens when the windows application is started using their libraries/components. I need to run an autoupdater independently of the app I'm trying to update - so I need to first get all users to run a setup.exe which should install and start my windows service so that it can run with windows daily to run a program to check, download and install the update.
I found some sample code for writing windows service on stackoverflow, codeproject also, but couldn't find how to autoinstall it (ideally with no UAC hassles for newer windows versions). All required using instalutil or some other manual process to install and start the service.
Any guidance on this would be great! Thanks - and apologies to the long winded question. Will update with additional results as I try out other products.
As you mentioned Npackd I would like to describe how this can be done using it.
I agree with selbie that the simplest solution would be to just create a task with Windows scheduler.
For Npackd you would need your own repository - an XML file accessible via HTTP, for example as http://www.yourserver.com/rep.xml . Here is a simple example for a repository: https://gist.github.com/raw/4132983/dabecde48c796d4fdfa2f645bb744ac58640572c/TestRepository.xml . A user would download Npackd (http://code.google.com/p/windows-package-manager/downloads/list) and add the URL to the list of repositories.
I would define 2 packages: one for the program itself and one for the auto-updater. This way if somebody wants to update the program manually, he can do this too.
You could create or delete a Windows task using the command line tool schtasks.exe available on every Windows system.
The update command itself would be also very simple:
npackdcl update --package=<package>
In order to eliminate the manual process, I'm researching how to run a program automatically on windows (I assume that means a service) which will check my server periodically for an update, download it and automatically trigger the setup.exe (or some similar process to get the patch files replaced).
You likely want the Windows Task Scheduler service for the "periodic" part of your statement. You use that to launch whatever code you would need to actually do the "check for update", download, copy, etc... I don't think you need a Windows Service.
You can likely script a Task Scheduler event. Or do it more programmatically with the API.
You can do as follow:
Maintain the version of the of the dll,exe etc in DB.
Check the version of the Installed version with the version in DB, before the application start up.
If the versions are diff, ask the user to update to the latest version from server.
If he clicks on YES. Update the files from server.
Prasad.