I am having trouble running batch files on Windows 7 that I created, and which run properly as Scheduled Tasks, on XP. When I run these batch files as Scheduled Tasks on Windows 7, the command window just closes quickly. The batch files actually consist of a wrapper that initiates another batch file that contains branching and call Python scripts - so it's a little complicated.
I'm comparing differences between my Windows 7 and XP machines. When I run these batch files on XP, the top bar in the command window says C:\WINDOWS\SYSTEM32\SVCHOST.EXE. I set up a simple batch file (that doesn't contain a wrapper, branching or Python scripts) on the Windows 7 computer and at the top it says taskeng.exe, please see capture below.
Does anyone have a suggestion on what I need to do to get the batch files running on Windows 7 as scheduled tasks? Maybe there's something missing from my Environment Variables? I have checked the paths and everything in my more complicated batch files that I transferred to Windows 7 - I should say I can get the batch files running when I actually navigate to folder containing batch files I created. I really need them to run as Scheduled Tasks. I'm not particularly savvy with batch files, but these were running really well for 1+ year on my XP computer. Thank you! Patty
On Windows 7 when creating a a Scheduled Task you can choose 'Start In' you can then change the location in which it is run (and the directory to file you are refering to within your batch file.) This is worth trying before checking other things.
Second I would check what permissions it is being run with on Task Scheduler, run it as administrator to rule this out.
I would also see what happens when you just double click on the batch file as a logged in user and go forward from that.
Related
I have created a basic .bat and a .vbs script in Windows 10. Now I want the script to automatically place itself in startup folder whenever it is opened for the first time. Any suggestions how to do it?
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.
I have created a batch file which starts a command line (IrfanView) with several arguments. The batch looks like this:
start /wait /d "C:\Program Files (x86)\IrfanView" i_view32.exe C:\Source\*.png /advancedbatch /convert=C:\Destination\*.jpg
Basically it converts all PNG from source folder to JPEG using advanced batch settings stored in INI of IrfanView to destination folder.
The batch file is located on my server (same as IrfanView) and when manually started it works fine. I also tried to start the batch using SSIS execute process task, which also works when package executes manually.
Another option was to start IrfanView directly from the execute process task (so no batch file) and then manually trigger the package. Every option seems to work manually.
However, whenever I try to run the batch (cmdExec) or any package in SQL Agent it will run the job successfully, but... there is no output in the folder. So, it doesn't give an error, it simple does nothing.
When run manually the output files will appear as expected in the destination folder.
When run through SQL Agent no output files will appear although the job was run successfully.
Could it have to do with security settings? SQL Agent runs under local user with full administrator rights.
I have read something about credentials and proxy, but not sure how to use it and if it will solve the problem.
I have another job running which also calls an executable (7zip) in a SSIS package and it works fine.
If I use another program, for example Flash Renamer from command line, then the SQL Job keeps running (status in progress), while triggering the package or batch manually it works fine.
Using SQL Server 2008 (BIDS + SSMS)
How can this be resolved?
Command start often interprets first double quoted string as title string. Therefore it is necessary to specify a title in double quotes if any other string must be enclosed also in double quotes.
IrfanView does not require that its program directory is the current working directory. Therefore simply starting IrfanView with full path would be better in my point of view.
IrfanView option advancedbatch requires data from i_view32.ini. On running IrfanView with a different account, it will be necessary most likely to specify the path to the folder containing i_view32.ini.
i_view32.ini is usually stored either in program files directory of IrfanView or in directory "%APPDATA%\IrfanView".
The first option is usually not used anymore as default program files location "%ProgramFiles(x86)%\IrfanView" on Windows x64 or "%ProgramFiles%\IrfanView" on Windows x86 is write-protected by default for users of Windows Vista and later Windows versions.
Therefore i_view32.ini is nowadays by default in application data directory of IrfanView of current user account.
Yes, environment variable APPDATA contains name of the user account and differs therefore from user account to user account. And by default user X has no permission to access the application data directory of user Y.
So on running IrfanView with a different account, file i_view32.ini or a copy of it containing the advanced batch conversion options must be located in a folder readable for all user accounts or at least the used account and on command line the path to this folder must be specified, too.
With summarizing up all information above, you would need most likely
start "Convert PNG to JPEG" /wait "%ProgramFiles(x86)%\IrfanView\i_view32.exe" C:\Source\*.png /advancedbatch /convert=C:\Destination\*.jpg /ini="Path to folder with i_view32.ini" /cmdexit
But below should also work if the batch file does not contain any other commands and therefore no batch file is needed at all.
"%ProgramFiles(x86)%\IrfanView\i_view32.exe" C:\Source\*.png /advancedbatch /convert=C:\Destination\*.jpg /ini="Path to folder with i_view32.ini" /cmdexit
I need to run a *.bat or *.exe file, but before windows start.
There are some programs to manage partitions that do this, for example "Acronis Disk Director Suite" allows you to create a new partition within Windows and then it asks you to restart the PC, when you do this you will see a script running and modifying your disk and then Windows starts and you have your new partition right there.
What I want is just to be able to run a *.bat or *.exe file the same way.
as far as I am aware you can't run a windows file (.bat is a windows thing) without running some form of windows.
running an exe file is possible, but you would have to write it to interact with the hardware without any drivers.
if you just want it to run at startup of windows, google "windows reg startup" (no quotes).
or put the file in
"C:\Users\username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
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.