I have a simple batch file set up on a 64-bit Windows Server 2008 R2. I'm trying to set it up to run under the Windows task scheduler, specifying the admin account as the user. I have no problem running the batch file manually, when logged on to the server with the same admin account. When in the Task Scheduler though, the task just Runs and hangs.
Here's the code from the batch file, moving files from a mapped drive to which the admin account has access:
DEL "O:DEL "O:\Finance file\AP\Check Run Merge\*.*" /Q
copy "O:\Finance file\AP\Invoices\ADT SECURITY_549527511_2015-05-12_655.32.pdf" "O:\Finance file\AP\Check Run Merge\142000.pdf"
copy "O:\Finance file\AP\Invoices\CENTRAL DRUG SYSTEM_244658_2015-05-08_3.50.pdf" "O:\Finance file\AP\Check Run Merge\142001.pdf"
copy "O:\Finance file\AP\Invoices\DATAFLOW BUS.SYSTEMS_156290_2015-05-20_7.50.pdf" "O:\Finance file\AP\Check Run Merge\142003.pdf"
I have just run a batch file from task scheduler using the following settings for the Action on Windows 7. The main part I got wrong the first time was not running it using cmd.exe. Also adding the /c so that the cmd closes after the batch file has run (that is probably why it takes forever).
I made my batch file write to a log file as follows so I could see that it was running:
time /t >> C:\temp\mytestlog.txt
just run it as a cmd.exe with the bat file as an arg. you could also short cut it and run that
Related
I am using Jenkins 2.46.1
I have a build pipeline plugin installed and I want to execute a Windows batch file in it. The batch file should execute in a new command window and not on jenkins console output. I give the below Jenkins pipeline groovy script:
node {
stage 'Init'
bat '''
call C:\\myprj\\mybat.bat stop
EXIT /B 0
'''
stage 'Deploy'
bat '''call C:\\myprj\\mybat.bat'''
}
In the init stage, I want to kill the process if it is already open and in stage deploy it should open a new command window and run my batch file.
The problem is that the above does not work. The build is succesful but no command window opens up. Pls suggest
Technically, to do what you're asking you should be able to run
bat 'start cmd.exe /c C:\\myprj\\mybat.bat'
This will launch a new command windows (cmd.exe) and run the batch file given. Depending how your Jenkins slave is running you may not see anything. (eg if it's running as a windows service or different user, you won't see anything)
Alternative solution if the agent is running in a service and you would like to get output:
bat(readFile("mybat.bat"))
Note: The bat file will need to be in your workspace.
Additional Note: You are no longer running the bat file from its original location. Instead it is being run from a temp location created by the underlying durable task system. This means things like %~dp0 in your script are not going to return the paths you might expect.
I have a batch on my C:\TEMP\batch.bat who runs an exe from a remote server (\Remote_host\App_Folder\app.exe)
My .bat content:
start /d "\\Remote_host\App_Folder\" app.exe
On double click, the batch file runs app.exe correctly. So now, I create a task in Windows Task Scheduler which triggers this batch file.
When task is launched, app.exe is not called.
Any suggestions ?
The task has to run with a specific account and make sure the checkbox "Run whether user is logged on or not." is not checked.
If checked, it will not store the password.
I know there are similar questions already out there, but none of the other solutions seem to help.
Using Windows 7, I have an executable (for this explanation, I am calling it test.exe) that takes a parameter of the current date.
Example when using the run command:
c:\test.exe 12/26/2014
The executable needs to be ran on a daily schedule.
I have the following batch file set up to run the exe with the required parameters:
#echo off
::This batch will be ran daily to start the exe program
set dateFormat=%DATE:~4,2%/%DATE:~7,2%/%DATE:~10,4%
echo Batch started %dateFormat% %Time%>> BatchLogfile.txt
set testfile=C:\test.exe
start %testfile% %dateFormat%
pause
I can run the batch successfully by double-clicking on it in explorer, but when I add it as a scheduled task it does not actually start the exe.
The batch does run and I can see the processes for the cmd and the exe, but the exe "interface" does not pop up. The echo line in the batch writes out to the log file successfully.
On the scheduled task, I am currently using cmd for the program/script and the following params:
/k "C:\test.bat"
I have also tried the following arguments unsuccessfully in the task scheduler:
C:\Windows\System32\cmd.exe
/c start "" "C:\test.bat"
/k start "C:\test.bat"
Is there anything else I should try so that the exe "interface" shows on the screen? Perhaps there is a better way to run the exe other than task scheduler?
If you want to see the GUI for test.exe, then you will need to configure the respective Windows Scheduled Task to "Run only when user is logged on". Of course then the process would only run for the configured user account.
This is available to select in the Security Options section in the General tab of the respective scheduled task.
I have a simple batch file which calls a powershell script.
I've looked at the following 3 previous questions on the subject as well:
Run a batch file from Task Scheduler is not working with a java command
Windows Task Scheduler doesn't start batch file task
Task Scheduler not executing batch (bat) file with MSTest commands
It seems like I've tried every single combination of running the task and it still doesn't execute my powershell script.
batch file contents:
powershell.exe "E:\SIS\fileCopy.ps1"
If I run the command in the batch file manually, it runs just fine. Here are things I've tried to do to get it working:
I've change the Security options to run as System with "Run with highest priveleges" checked
I've tried every other combination of "Run only when user is logged on", "Run whether user is logged on or not" and "Run with highest priveleges"
I've tried adding the "Start in (optional" setting to the folder where the files are located.
I'm at my wits end and can't believe Microsoft hasn't figured out a way to make this easier.
You need to have task scheduler execute Powershell.exe and have the arguments be the path to your .ps1 file.
To validate your script is running properly, you should set the Security options to 'Run only when user is logged on'. It will then pop the powershell dialog when it runs. I often also use start-transcript to view the results of scheduled poweshell scripts.
After you validate the script is running correctly, you can set the security options however best fits your situation.
Use the execution policy flag to flag that instance to unrestrisicted because your powershell settings may be blocking script execution.
powershell -executionpolicy unrestricted -Command "E:\SIS\fileCopy.ps1"
I found that Task Scheduler can't run a batch file if it lives in a folder that is being synced by OneDrive. I had to move the batch file to another folder to get Task Scheduler to be able to run it.
quick explanation:
I have a batch file converting a series of swfs to mp4s which are placed into the batch file via PHP fwrite. This is ran every hour on windows Task Scheduler. For example:
C:
cd "path\Moyea\SWF to Video SDK"
swf2videocmd "conversion_command_here"
cd "path\MySQL\bin"
mysql --host=hostip --user=user_name --password=hostpw--database=database_name --table=table --execute="UPDATE table SET processed=1 WHERE processID=44;"
This works fine, updates the SQL and runs the process. There can be as many conversions in one batch file as necessary, they're added dynamically on demand. Windows Task Scheduler runs the batch fine aswell.
I then have a secondary batch file which Task Scheduler runs at the same time - clear.bat. This clears the first one so the conversion job can start afresh with the new files next time:
D:
cd "path\youtube\"
nul > swf2mp4.bat
It clears the first batch file fine, but returns a prompt saying Windows cannot access the specified device, path or file.
In windows Task Scheduler, it can't close this prompt so the task gets stuck running, meaning the next instance of the task (hourly) can't be run. I would make it automatically close each hour, but the conversion queue may be large. All I need to do is supress the error.
Replace
nul > swf2mp4.bat
with
type nul > swf2mp4.bat
and it should work fine.