How to keep any program on Windows Startup with batch command - batch-file

I want to run batch file on windows startup working with Windows 7, Windows 8 or Windows 8.1 which will start automatically on Windows Startup from any location of PC so that whenever PC start it will run automatically. Is there have any way to do that ?

you can use the task scheduler for that,
Action: Start a program
Program/script: path to your batch file : "c:\my\batch.bat"
Add arguments (optional): add here start parameters
Start in parameter (optional): Fullpath of your bat file location (needed if librarys are attached)
alternatively there is C:\Windows\System32\gpedit.msc
There you can easily navigate to adminstrative templates --> logon and add your script

A third method (and possibly the easiest) is to copy your files into the GP machine scripts startup folder.
C:\Windows\System32\GroupPolicy\Machine\Scripts\Startup
C:\Windows\System32\GroupPolicy\Machine\Scripts\Shutdown
Also works from the $OEM$ folder in case any readers are doing fresh installations.

Related

Batch File to start application restarts itself again and again

I'm trying to create a batch script to activate a conda environment and start an application within it (which has been previously installed).
But for whatever reason, the application doesn't start but the batch script itself restarts again and again.
I'm using the following script:
#ECHO OFF
ECHO Activate Environment ...
call activate ENV
ECHO Start application ...
ApplicationName
PAUSE
The output if I start the batch script by doubleclicking it is:
Activate Environment ...
Start application ...
Activate Environment ...
Start application ...
Activate Environment ...
Start application ...
I also tried with call ApplicationName and start ApplicationName but this doesn't work either. The application I would like to start is an own application which can be installed via pip (Python application, entrypoint specified in setup.py).
The normal use is to open a cmd or the Anaconda prompt, activate the environment manually and enter the command ApplicationName on the command line. After this the application triggers a browser window to open a login screen. When I use the application like that the command line window stays open during the execution of my application and prints debug messages.
I just don't understand why the commands are repeated again and again instead of that the application is started.
Do you know what causes the behaviour?
Thank you in advance for an answer!
Best Regards
Your batch file has the same name as your undisclosed ApplicationName.
Therefore the batch file will restart ApplicationName.bat instead of ApplicationName.exe

Executing directory Changes when launched from windows explorer as administrator

I'm using a .bat file for installation purposes and I'm using ".\" very often when I need to access files (for example for an unzip) in order so get which directory I'm in.
It worked quite well until yesterday when suddenly I had 2 different behaviours:
Lauched from command console (with the console inside the directory): The file works as normal and knows where .\ is at.
Launched from windows explorer it also functions if it is not started with administrator rights
If launcehd from windows explorer with administrator rights the executing directory (thus the directory which is printed with cd if its the first command in the .bat file) suddenly is c:\windows\system32
This behaviour like I said started just a few days ago (2 days ago we saw it for the first time when we tried that .bat file), before that it worked from windows explorer exactly the same as from the command console.
So my question here is twofold:
Is there anything known as to the cuase of this changed behaviour?
How can I get a handle to the current directory that the .bat file is located in (because the .zip file will always be in the same directory as the .bat file itself), thus how can I solve this problem as I need to start the file with administrator privileges
I found that there is a similar issue in windows vista:
Windows batch file starting directory when 'run as admin' although what intrigues me there is why the problem did not appear for weeks and only appeared recently with windows 8
Use this as the line after #echo off:
cd /d "%~dp0"
It will change the working directory to be where the batch file is located.

Copy file before include it in the installer package NSIS

For example I have a config file in D:\Project\InstallerPro\Platform\Windows8\Web.config
I need to move that file to D:\Project\InstallerPro\Web\Configuration\Web.config if the windows version is windows 8
After that, the installer will be generated from a nsi script in D:\Project\InstallerPro\PROinst.nsi
Is it possible to copy the files (not manually) before compiling it into an installer using NSIS?
I want to do something like this:
CopyFiles ".\Source\Platform\Windows8\Web.config" ".\Source\WEB\Configuration\Web.config"
CopyFiles is a runtime command, i.e a command that will run during the installer execution and not during the installer creation.
You could use the !system command that is executed during the compilation of the installer, e.g.:
!system `copy "c:\Source\Platform\Windows8\Web.config" "c:\Source\WEB\Configuration\Web.config"`
You will need to use absolute paths as the current working dir is from makensis.exe and not from the script being compiled.

how to make a bat file autostart in win system

I have a bat file (in fact it is a tomcat startup bat), this is the very simple content:
c:/tomcat/catalina.bat run
Now I want it to autostart at system startup, any ideas?
To clarify more what #Oskar said. The autostart is the startup folder in your Program Files folder.
Any executable files placed in that folder are launched on windows startup.
if you want to start it when you are logged in then put it in start list, just create shortcut to bat file in startup folder start->programs->startup

Launching .bat files on Windows with Adobe AIR NativeProcess, not supported?

I can easily start "sh" files on Mac, but when I try the same with bat on Windows I get this:
The NativeProcess could not be started. 'Files with '.bat' extensions cannot be launched.'
Rename the file from *.bat to *.cmd and it works like a charm.
So much for security.
For security reasons, you can't do that.
AIR on Windows does not allow you to run .bat files directly. Windows .bat files are executed by the command interpreter application (cmd.exe). When you invoke a .bat file, this command application can interpret arguments passed to the command as additional applications to launch. A malicious injection of extra characters in the argument string could cause cmd.exe to execute a harmful or insecure application. For example, without proper data validation, your AIR application may call myBat.bat myArguments c:/evil.exe. The command application would launch the evil.exe application in addition to running your batch file.
If you call the start() method with a .bat file, the NativeProcess object throws an exception. The message property of the Error object contains the string "Error #3219: The NativeProcess could not be started."
Instead, try starting cmd.exe with the arguments /c your-batch-file.bat.
var batUrl:String = "outProtoCmd.bat";
var file:File = new File(batUrl);
file.openWithDefaultApplication();

Resources