Use task scheduler to choose .ini config files for a program to use depending on network status - windows

I would like to examine the possibility to start a program with task scheduler. The program is starting with different config .ini files depending on the network status (online/offline)
This is managed with a script today but i,m curious if this is possible to do with the task scheduler.
I,m not asking for a complete solution but if i even should consider it.

Related

Start instances of scheduled task at windows startup consuming same exe file

I installed 3 scheduled task and triggered them with Windows startup.
After disabling hibernation, this worked fine only on one random task after several tries.
All of them consuming the same exe file with different parameter.
I then created 3 binary folders for 3 different locations of the exe file and its binaries and it turned out, that this works.
Problem is, that I want to create much more scheduled tasks with the same exe and calling with different arguments.
So the question is. Do I really have to copy new folders for every new task?

Windows Task Scheduler - Copy file from URL to Desktop

I'm wanting to create an automated job in Windows (presumably using Task Scheduler) to copy a CSV file from a URL to my desktop. From what I can gather, a batch file cannot copy a file from an external location. Not familiar with Powershell, but it looks like it might have that capability.
What is the best way to create a script and automate the process to copy a file (http://example.com/file.csv) to my Desktop for instance? Would like to use features native to Windows without having to download a third-party application if possible.
Thanks for any and all help!
You can download a file using powershell using syntax like this:
$client = new-object System.Net.WebClient
$client.DownloadFile("http://example.com/file.csv","C:\tmp\file.txt")
Save this as a script (something.ps1). Then create a task in the Task Scheduler and add a new "Action" of the type Open Program. Use program PowerShell, and specify the path to the script (like C:\something.ps1) as the argument.
More info:
How to download files using powershell
Scheduling Powershell script execution
Windows Scripting Host does allow you to get files via HTTP.
See AnthonyWJones' answer at HTTP GET in VBS
Change code as appropriate, save as .vbs file, schedule same.
I know very little about powershell so I don't know if it can do it. I know you prefer not to use a third-party application, but you can easily do what you want with curl which comes as a single stand-alone exe: http://curl.haxx.se/dlwiz/

Where does Windows store the settings for Scheduled Tasks console?

I would like to know where Windows stores information for Scheduled Tasks. I would like to be able to find the reference for the name, schedule, or command to run associated with a given task. This may not be practical or possible, but I would also like a means to edit the scheduled tasks and their attributes outside the Schedule Tasks console. I've assumed that the data would be in the Registry somewhere, since I doubt it would be stored in a normal file, but I'm uncertain where I should be looking.
Windows stores scheduled tasks as XML files, AND in the registry.
You can find them in a few places:
Filesystem:
%systemroot%\System32\Tasks
%systemroot%\Tasks
Registry:
HKLM\Software\Microsoft\Windows NT\CurrentVersion\Schedule\Taskcache\Tasks
HKLM\Software\Microsoft\Windows NT\CurrentVersion\Schedule\Taskcache\Tree
Note: You can't edit the XML files directly in \Tasks for security reasons. See here for more information: https://serverfault.com/questions/440496/ok-to-edit-tasks-xml-file-in-c-windows-system32-tasks
To work with importing the XML files without going through the scheduled task UI you can look at these:
Schtasks.exe
Powershell Scheduled Task Cmdlets
In Windows 7 they are stored in files under "Windows\System32\Tasks". The files are XML, so you could create and edit task files there.
Other versions of Windows I think they are stored in "%SystemRoot%\Tasks"
I needed to delete some tasks as in a script as the final part of a system build.
I discovered you can just delete them eg:
#echo ..Audit hardware
"\\vs-files\General\0000 IT\Bginfo.exe" "\\czwgbak\Software\_Build2015\AuditWorkstation.bgi" /timer:0 /Silent /NOLICPROMPT
#echo delete Scan Setup inis
If not exist %systemroot%\System32\Tasks\ASUS\nul goto reg
rd %systemroot%\System32\Tasks\ASUS /S /Q
:reg
etc...

Task Scheduler to send Email through Batch

So basically I already have a batch script that would log some information in a text file. The thing is I want to have it send an email with the results. I was wondering if there is a way to do it using the task scheduler or something of the sort. I just want this thing to be automated without the use of any other software. I only want to use what is built in with the OS.
I would recommend using a VBScript... everything is built in and it is pretty darn easy.
Here is a write up: http://www.paulsadowski.com/wsh/cdo.htm
Another one: http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/enterprise/mail/
The easiest thing would be to attach your file as an attachment whose name doesn't change. So your batch would like something like (not tested)
.... your existing stuff .... > emailAttach.txt
cscript.exe theEmailSendingScript.vbs
del /f emailAttach.txt
That way the timer can kick this off and reuse the same filename. The vbscript can attach emailAttach.txt and it was always be the new file.
A couple solutions for future readers:
Task Scheduler can now send email as an action in a Task. I believe the feature was added to Windows Server 2008.
I have used blat.exe in batch files for years. Very flexible tool found here
Powershell's Send-MailMessage cmdlet

Windows: File Monitoring Script (Batch/VBS)

I'm currently in working on a script to create a custom backup script, the only piece I'm missing is a file monitor. I need some form of a script that will monitor a folder for file changes, and then run a command with the file that's changed.
So, for example, if the file changes, it'll execute "c:/syncbatch.bat %Location_Of_File%"
In VBScript, you can monitor a folder for file changes by subscribing to the WMI __InstanceModificationEvent event. These articles contain sample code that you can learn from and adapt to your specific needs:
WMI and File System Monitoring
How Can I Monitor for Different Types of Events With Just One Script?
Calling WMI is fairly cryptic and it causes the WMI service to start running which can contribute to bloat since its fairly large and you really can't cancel the file change notifications you've requested from it without rebooting. Some people experimenting with remote printing from a Dropbox folder found that a simple VBScript program that ran an endless loop with a 10 second WScript.Sleep call in the loop used far less resource. Of course to stop it you have to task kill that script or program into it some exit trigger it can find like a specifically named empty file in the watch folder, but that is still easier to do than messing with WMI.
The Folder Spy http://venussoftcorporation.blogspot.com/2010/05/thefolderspy.html
is a free lightweight DOT.NET based file/folder watching GUI application I'ved used before to run scripts based on file changes. It looks like the new version can pass the event filename to the launched command. The old version I had didn't yet support file event info so when launched, my script had to instance a File System Object and scan the watched folder to locate the new files based on criteria like datestamps and sizes.
This newer version appears to let you pass the file name to the script if you say myscript.vbs "*f" on the optional script call entry. Quotes can be important when passing file paths that have spaces in folder names. Just remember if you are watching change events you will get a lot of them as a file grows or is edited, usually you just want notification of file adds or deletes.
Another trick your script can do is put the file size in a variable, sleep for a few seconds, and check the file again to see if its changed. if it hasn't changed in a few seconds you can usually assume whatever created it is done writing it to disk. if it keeps changing just loop until its stable.

Resources