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.
Related
for using the latest version of our templates, I want to copy the templates from our server to the user's local machine. but I want the templates will be copied to the local machine when the PowerPoint load and runs. I created a batch file to copy templates from server to local machine and I am looking for a way to run automatically this batch file after each time PowerPoint running.
I convert batch file to exe file that first copy templates to a local machine then run PowerPoint.exe.
with that method, my problem has been solved and it works fine.
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.
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.
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.
What is the default SSIS Account that is used in SSIS packages.
In one of my packages I have a Data Flow task that creates a flat file. A BAT file later runs and creates a file based on information in that .txt file. If I execute the .BAT in Windows Explorer it runs fine. When SSIS tries to execute it I can see the CMD window open and it tries to access the txt file and isnt able to. Says "Unable to access nameoffile.txt"
I assume the issue is that the permissions are probably inherited by the SSIS user account so I am trying to figure out which account that is.
If you are running it from the IDE then it uses your permissions. Most likely the problem is that your file is locked by some other process in your SSIS package. To verify:
Add a PAUSE to your batch file to make it wait for any key.
Run your package. While the dos prompt is waiting, go into windows explorer and run your batch file again - you'll find the same error.
I changed the attrib value in dos for that specific folder by attrib -r -s and it worked. It thought it was read-only.
I am using Windows Server 2012 server, with a SQL Server 2012 database.
Adding Modify, Read, Write permissions to the folder containing the required file to the NETWORK SERVICE user seems to work for me.