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"
Related
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
My computer shuts down every night starting at 9:59 and continuing until 11:59. I do not know why. I'm wondering if a .bat file could be written to automatically abort the shutdowns, or at least require confirmation?
It seems some unwanted software installed in your system. Check in the startup directory, remove any unwanted exe or batch files.
Check the scheduled task in windows using below command in older windows
at
After windows 7
schtasks.exe
Delete the unwanted tasks. Scan your system using Windows Defender
Below is the command used to abort the shutdown.
shutdown -a
This is the .bat file I am currently working on:
#echo off
net use \\servername\ /user:admin admin
call "C:\Documents and Settings\admin\Desktop\RBDPAY.bat"
exit
However when running the .bat file from local machine it give me this error:
The system cannot find the path specified.
SysInternals has a tool called psExec that does just that.
PsExec is a light-weight telnet-replacement that lets you execute
processes on other systems, complete with full interactivity for
console applications, without having to manually install client
software. PsExec's most powerful uses include launching interactive
command-prompts on remote systems and remote-enabling tools like
IpConfig that otherwise do not have the ability to show information
about remote systems.
Your example would look like this:
psexec \\servername"C:\Documents and Settings\admin\Desktop\RBDPAY.bat"
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.