Windows Task Scheduler - Copy file from URL to Desktop - windows

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/

Related

Self-extracting file that takes arguments and return exitcode

I want to create a self-extracting file (SFX) named Setup.exe which contains a Windows application with some dependencies.
It is possible to start the Windows application with arguments, and I would like to put them at my Setup.exe and then it should pass them to the Windows application. Furtermore, I would like to pass the Windows application exit code to the Setup.exe.
Currently I have tried to use 7zip, but it seems that it isn't sufficient.
Is it even possible with 7z or do you know how to do with other tools?
You've asked a lot of questions and I am trying to answer a few here, maybe not all of them.
Yes it is possible to start a Windows Application with arguments. Ideally for that you need to open command prompt and navigate to the directory of your application then type in theProgramName.exe - arguments options but that I assume you already know.
Another approach would be to Create ShortCut for the Program you are targeting and then you can just Right click -> Properties -> and append your arguments to the Target field. Example : C:\Games\Counter-Strike\hl.exe -steam -game cstrike -noforcemparms -noforcemaccel
Another approach that I assume you would want when you are creating a SFX is to create a .bat (batch) file with the contents being theProgramName.exe - arguments options and put it in the same directory as your program and set it to run as our main application when it extracts. If you want the exe and not the bat you can use some bat to exe conversion tools, there are tons out there.
The best way I can think of is using programs like Advanced Installer. You can directly make an msi or a sfx and send a shortcut anywhere (more than one) and it could contain arguments you specify just like what I described in the second way.
So yeah that other tool I'd vouch for that will do what I think you want to do is Advanced Installer.
After some experiments, I changed the implementation so instead of using 7 zip to create a SFX I just embed all I need like *.msp and such as embedded resources in my Windows application.
On that way my arguments and return code worked out of the box.
I used this link to do actual implementation: https://www.telerik.com/blogs/how-to-merge-assemblies-into-wpf-application

FTP Jar file from share path on windows to IFS location in AS400?

I am looking for an approach / design through which i want to automate the process of FTP from windows location to IFS location present on AS400 environment when ever there is a new file added to windows path.
Below is the approach I thought, Please refine it if needed.
We have an option WRKJOBSCDEthrough which we can run a CL program in a scheduled threshold of 1hr.
To write a CL program which invokes a script(pyton/shell) to talk to windows location(say X:drive having its IP as xx.xxx.xx.xx).
Shell script has to search for latest file in the location X:drive and FTP that jar(of size 5mb max) to IFS location(say /usr/dta/ydrive) on AS400 machine.
Thus, CL program we invoked in STEP2 has to mail to me using SNDDSTthe list of all the jars ftp'd by the scheduler job that runs every 1 hr in STEP1.
All I am new to CL programming/RPGLE . Please help me with some
learning stuff and also design of such concepts.
You could use a library like the one provided by Scott Klement at https://www.scottklement.com/ftpapi/ to roll your own automation client. It was designed to be used from RPG, and is easy to use. From there it is a simple task to:
retrieve a list of files in the directory
parse the list to retrieve file timestamps
get any files with a timestamp later than the last successful run
The CL command RUNRMTCMD can be used to invoke a command on a PC running a rexec() client. iSeries Access for Windows offers such a client, and there are others available. With the iSeries client, the output of the PC command is placed in a spool file on the AS/400, which should contain the results of the FTP session.
You can copy the spool file to a file using the CPYSPLF command and SNDDST it to yourself, but I am not sure the contents will be converted from EBCDIC to ASCII.
Check out Easy400.net for the MMAIL programs developed by Giovanni Perotti. This package includes an EMAILSPL command to email a spool file. I believe you will need to pay $50 for the download.
I think you are on the right track, but the are a lot of details.
You have to learn to program windows. dotnet filewatcher Out of scope for a complete answer. All of the other solutions seem to be polling solutions "Are we there yet?" "No were not there."

It's possible to execute one script when i add a new file to one folder?

I want to make a script on windows to move my files on folde1 to folder2 when i add some new file in folder 1, is it possible or at least any part of this?
Yes, it's possible. You can use:
Powershell (example)
Batch file, with or without task scheduler (example on link above)
Task Scheduler and a VBScript (example)
VBScript and WMI __InstanceModificationEvent event (reference)
.NET's FileSystemWatcher (example)
Third party software (some suggestions)
Concept is called DirectoryWatcher/FileWatcher, you can google it by these keywords for your programming language. It's represented in most languages now.

Building a Visual Basic script that uses a batch file

I've written a batch file script that takes an image sequence from a certain folder, converts it to quicktime using ffmpeg and then it moves the file to a certain folder.
I used variables at the beginning of the batch script for user input on which folder to take the files from.
And now for my question: The batch I've written works just fine but I want to make it into a simple visual basic script so it looks nice and clean instead of a command prompt interface.
Can anyone provide me with tips for the VB code?
How do I pass variables from VB to the batch file?
Any help on this would be much appriciated.
Use a HTML Application to program the GUI to gather the info needed from the user. Use WScript.Shell's .Run or .Exec method to start an external process (either the .bat or ffmpeg directly) and pass those info via the command line.

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

Resources