Running batch files on a schedule - batch-file

I have a machine that I connect to it remotely by Remote Desktop connection and I map it's IP and can connect to it's hard drives.
Every morning I run 3 batch files that pull text data from the machine.
Is there a way through Batch commands to automatically run those 3 files as a schedule task every morning at 7:00AM from example?
I searched answers for this issue and most of them answered to do that through Windows schedule task, but it is not working for me due to the Remote connection. Thanks!

Related

Batch script to check if rdp connection is down, then reconnect

I want to create a batch script that outputs all of my current rdp connections. I am connected to multiple machines from my desktop, but lose connection to them every so often. Eventually, I'd like to schedule this task to run regularly and notify me so that I can go in a reconnect. For reference, I am using a non-admin account.
Update:
With the query posted below (found in another stackoverflow post), I am able to get a list of all connections listening in on port 3389. In a limited use environment, these should only be RDP connections.
netstat -n -a | findstr 3389 >"C:\Users\Public\log.txt"
Edit 1: Reworded question.
Edit 2: Found temporary solution.
Original question:
The goal is to to schedule a task that checks a PC every XX minutes to
see if it is connected to some VM's via Remote Desktop Connection. If
it isn't connected to the right VM, then attempt to reconnect. I
understand that I will need to schedule a batch file to run every XX
minutes, then have the batch file check the connections (the hard
part). I have looked around and I cannot find a clear answer as to
whether this is even possible.
While not a batch solution, powershell is available for Most Windows Machines
Powershell
Using PowerShell
=======================
import-module remotedesktopservices
Get-RDUserSession
Results
CollectionName DomainName Username HostServer UnifiedSessionId
============== ========== ======== ========== ================
Session Coll.. LocalHost joe d103joe 14

VbScript or with Scripting

we need to execute scripts locally, but how can we do it from a remote machine, so as to avoid going on to each machine and triggering the process manually. preferably with VbScript.
Generally in your VBScript you will specify the machine you want to query with the line
strComputer = "."
This can be changed to a computer name or IP address to remotely query a machine. However it is difficult to provide anything further as you've not posted your script or what you're trying to achieve with it..
Write your .vbs scripts and deploy them to a remote server - then on the remote server schedule a task to run whenever you'd like the script to run.
The script will run locally on that server.

Remote exectution of bat file through Winform

There are bat files on some servers that we have. I have Winform app that can view directory files and executables on different server. Is there a way that (based on the selected bat file), to be be able to run that bat file on that server from the Winform app.
Not in the way you are thinking. If you run a batch file from your machine (via app or manually) it runs locally on your machine, not on the remote server.
If you can install software, PsExec maybe be a good fit. If not, I have a couple of options I can think of.
Alternatives: create an app that runs on the server that knows when to run the batch files (via messaging, database records, etc) or use the Windows Task Scheduler.
The Task Scheduler approach is fairly simple. You could have the batch files set to run every one minute and at the start of the batch file, you do a file check. Your WinForm would create that file and at the end of the batch (if the file existed at the start) it would delete the file that triggers the batch.

Connecting shared network drive through scheduled task

Actually, i have one scheduled task in my application to trigger multiple batch files based on timings ( maintaining like crontab). I dont want store the password of the my account, i have selected "Do not store password" option when i created schedule task.
Now, i tried to connect the network drive through one pf the batch file which is triggered by this schedule task, i am getting access is denied error.
When i run the batch file normally (not triggered by schedule task), it is working without any issues.
Could you please help me to connect the network drives through the schedule task.
Thanks,

Batch file's Core FTP line is Not running during Scheduled Task. Works if started Manually

I have a simple batch file which needs to be run weekly to upload some files via Core FTP.
I'm using the free version of Core FTP LE.
MySavedProfile is the Site Name of the saved profile I created using Core FTP's site Manager. The profile contains the URL / credentials / etc of the site to connect to.
Here are the contents of the batch file:
SET logf=confirm.log
echo test-start >> %logf%
"C:\Progra~1\CoreFTP\coreftp.exe" -B -s -pasv -O -site MySavedProfile -u "C:\Progra~2\PathToFiles\FileToUpload.txt"
echo test-finish >> %logf%
For the Windows Server 2012 r2 Task Scheduler, I have created a basic, weekly scheduled task on the Task Scheduler Library root which runs the batch file. For this scheduled task I have:
(Under the General tab)
"Run whether user is logged on or not" is selected
"Run with highest privileges" is checked
Configure for = Windows Server 2012 R2
(Under Actions)
Action = Start a program
Program / Script = "C:\Progra~2\PathToFiles\batch.bat"
Start in = C:\Progra~2\PathToFiles\
Here is the weird behavior I am getting:
If I double click on the batch file directly, it works fine and uploads the text file via Core FTP just fine.
However, if I try to let the Windows Task Scheduler run it, it runs everything except the Core FTP line. That is, I get the usual:
test-start
test-finish
in the confirm.log file, but the FileToUpload.txt has not been uploaded to the remote server, and there are no errors from CoreFTP that I can detect.
I have tried this with a service account that has permissions to run batch files, as well as my own account for this scheduled task. I get the same result: it doesn't seem to run that CoreFTP line. At least not via Task Scheduler. I need this upload to be automated.
I've searched Core FTP's documentation, Google, etc. No one seems to have run into this exact issue. I've applied recommendations from distantly related issues, but none of them have worked.
Any help would be greatly appreciated. Thank you.
The only way to do this is to use the full version of Core FTP (that is Core FTP Pro). If you use the LE version you have to check the "Run only when user is logged on" option.
This happens because of the splash screen at the beginning.
If you can't be logged on forever you could create a user that will always be logged on just for these tasks.
Remember to use the -Log option on CoreFTP to check if it is actually doing something.

Resources