Page 1 of 1
Start batch files at startup...
Posted: 21 Apr 2021 09:58
by rasil
Hey,
I want to create a batch file that when you run it, it puts itself in the startup folder or something like that. I searched on google and all the solutions require you to manually put them in the startup folder or make a regedit file. Is something like that going to be possible?
Re: Start batch files at startup...
Posted: 21 Apr 2021 11:04
by Maylow
Probably because by default access to "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\" is restricted for security reasons.
You can copy to the user startup folder %APPDATA%\Microsoft\Windows\Start Menu\Programs\StartUp\, no problem.
Code snippet of batch script that copies itself to user startup folder:
Code: Select all
copy "%~f0" "%APPDATA%\Microsoft\Windows\Start Menu\Programs\StartUp\%~nx0"
Re: Start batch files at startup...
Posted: 24 Apr 2021 03:39
by Hackoo
Hi
Just give a try for this batch file :
Code: Select all
@echo off
Title Create a shortcut on Startup Folder of my batch file using Powershell
::-----------------------Calling our Sub-Routine Create_Shortcut_Startup -------------------------------
Call :Create_Shortcut_Startup
::-------------------------------Begin Main Batch code here --------------------------------------------
echo Done and your main batch goes here !
echo i am a test
Pause>Nul
::-------------------------------End Main Batch code here-----------------------------------------------
Exit
::--------------------------------------------------------------------------------------------------------------------------
:Create_Shortcut_Startup
Powershell -C ^
"$s=(New-Object -COM WScript.Shell).CreateShortcut('"%AppData%\Microsoft\Windows\Start Menu\Programs\Startup\%~n0.lnk"'); ^
$s.TargetPath='"%~f0"'; ^
$s.Save();"
Exit /B
::--------------------------------------------------------------------------------------------------------------------------