How to schedule task with access to multiple drives? - batch-file

I am attempting to run a .bat file that within itself starts a pyton script that moves files within a directory on one drive to another directory on a different drive. I can run the file by hand successfully but when I schedule a task for it, the run result is 0x80070001 and:
The .bat file contains:
C:\Python37-32\python.exe "C:/wamp64/www/sgmvp_cloud_files/moveFiles.py"
How can I adjust my .bat file or the task itself to have access to both drives? I am running the task with the highest privledge and I am authorised to Log on as a batch job.

Related

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.

Windows 2008 R2 Task Scheduler fails to execute commands

On my Windows Server 2008 R2 machine, a batch file is scheduled to run using Task Scheduler. For some reason, only a portion of the commands in the batch file are executed; Some commands are ignored.
Batch file looks like this:
cd s:
cd "S:\Reports\"
sqlcmd -S ipAddress -U login -P password -d dbname -i "S:\query.sql" -o "S:\Folder\Report.txt"
copy /A /Y "S:\Folder\Report.txt" Y:\
When I run the batch file by double-clicking on it, everything runs as intended; But when it is executed from task scheduler, only the sqlcmd portion runs correctly. The copy command does not seem to run. Even when I replace copy command with xcopy or mkdir or any other command, it does not run.
Even if I change the order of commands in the batch file, the commands do not run. But when the batch file is executed by double-clicking, everything runs perfectly.
The Y:\ is a mapped drive under the same login. After typing my question this far, I went back and ran one more test. Interestingly, if I replace mapped drive with local drive, everything seems to be working okay. So, at this point it looks like mapped drive is the problem. Any ideas on resolving this?
Essentially, how to copy or move files to a mapped drive (different machine) using batch file executed from Task Scheduler?
S: and Y: are probably mapped network drives, but those are mapped in the context of a user session. The scheduled task will be run in its own session and won't have those drives mapped.
You should use the UNC path of the share instead (\\server\share) as that should work in either context (as long as the share is accessible to the user the scheduled task is running as).

Concatenate TimeStamp to File using Batch file

I have created two batch file that are working. Here is the outline
First Batch Calls another batch file
The second batch file changes to the directory on the application where the utility and command path to backup an asset resides, does the backup and places the file in C:\
I simple did a cd/ after the CALL command used to start second batch file to return to the path where the backup file is archived.
How do I use
set backupFilename=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%
or other function to Concatenate to the backup file?
FileName_05-21-2015:09:30 Pm.txt
I am getting an error that the file does not exist when in fact it does. My intention is to use AT command or Schtask command to schedule this backup process every week. I will also appreciate more descriptive application of this commands too with time stamp for every backup completed on schedule

batch how to add schedule backup to batch files

I have a .bat file that use xcopy to pickup users pst file from document and setting then copy it to a shared drive. users always for get to double click to run it. How can I add time and date for the .bat file to run on its own. Windows build schedule doesn't work at time. thank you!
Batch files can't run on their own. Something has to launch the batch file.
You can use Windows Scheduler to schedule the running of the batch file, and then test for the time when the batch file is run in the batch file itself. If it's not the right time, the batch file can just exit; if it is the right time, the batch file can do the backup.
Scheduled tasks can run at a specified time; I have one that runs every weekday (Monday through Friday) at 8:45 AM that runs a process to retrieve files via FTP.
If you need more information about using Windows Scheduled Tasks, you should ask a question about it at SuperUser; that subject is not programming-related and would be off-topic here.
No idea what you mean by Windows build schedule doesn't work at time and you don't say when you want this backup to run - hourly? Weekly? Once a day?
What you could do is investigate the use of the AT command - that may suit you. Perhaps install a batch to run AT in your startup directory.
Or perhaps it would be better to start a hidden batch from the startup directory and use the TIMEOUT or CHOICE command to make it loop periodically.
You would need to explain your requirement in more detail.

Task Scheduler Batch File with Configuration

I'm currently using APEX Data loader to download Raw files from Salesforce.
Using the command line I can download the data that I need by simply typing the command.
Now I need to schedule the task so I don't need to do it everyday.
I run the dataloader by typing in the following
C:/Program Files (x86)/salesforce.com/data loader/bin/process.bat C:/datadownload/
C:/datadownload contains the configuration file I need to connect to Salesforce.
How can I set this thing up with Task Scheduler?
Resolved By creating another batch file... CALLing the Process.bat and adding the location of the file
Create another batch file with the same command - note the double quotes - and schedule that batch file in task scheduler. When you've done that then launch the scheduled task manually (right click on the task) to test that it works. Provide credentials and an account if it is to run when you aren't logged in.
I added the call command in case you want to add any post-processing tasks to the batch file later.
#echo off
call "C:/Program Files (x86)/salesforce.com/data loader/bin/process.bat" C:/datadownload/

Resources