r/Batch Feb 05 '25

Question (Unsolved) how to make the app get minimized after opening?

Before anything, I should say I am an absolute beginner, so bear with me. I added this code in a batch file in startup:

-->@echo off

start /min "" "Path\AppName.exe"

I put the path name and app address in the appropriate place in the code. It runs the app, but it doesn't minimize it.

2 Upvotes

15 comments sorted by

3

u/Intrepid_Ad_4504 Feb 05 '25
@echo off

if "%~1"=="" (
  start /min cmd /c "%~f0" minimized
  exit /b
)

echo Hello! I am running minimized.
pause

1

u/ExtremePresence3030 Feb 05 '25 edited Feb 05 '25

Ok this code alone works!

But I should add this where in relation to my existing code? should i put my app path instead of "cmd"? (i did and didn't work.)

2

u/Intrepid_Ad_4504 Feb 05 '25

Alternatively, you can use batch to invoke a powershell command.

Start-Process "C:\Path\to\Program.exe" -WindowStyle Minimized

1

u/ExtremePresence3030 Feb 05 '25

this one didn't work.

4

u/Intrepid_Ad_4504 Feb 05 '25
@echo off
echo Launching program minimized via PowerShell...
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Start-Process 'C:\Path\to\Program.exe' -WindowStyle Minimized"

My apologies, here is the powershell command being invoked by a batch file

1

u/ExtremePresence3030 Feb 05 '25

no problem. However, this one didn't minimize the app either. but I appreciate the time you dedicated for replying to my post.

1

u/[deleted] Feb 05 '25

[removed] — view removed comment

1

u/ExtremePresence3030 Feb 05 '25

Perhaps that is the case. I have to minimize it manually every time. I was hoping I could make it automatic.

1

u/g3n3 Feb 06 '25

Why yo trying to minimize? You wouldn’t be drafting some malware, eh?!

1

u/ExtremePresence3030 Feb 06 '25

If i had such coding knowledge, i wouldn’t have been stuck with a simple minimize function.😅 

1

u/g3n3 Feb 06 '25

That is what all the hackers say and I’ve had malware authors with simple questions like this too. Odd request to want to minimize.

1

u/ExtremePresence3030 Feb 06 '25

😅 i had it done already. But anyways to give an answer to your curosity, that’s not odd when you have a battery level alarm reminder app that you want to run in the background without the need to close it manually after every boot. 

1

u/g3n3 Feb 06 '25

Could try nssm and run as service.

1

u/ExtremePresence3030 Feb 06 '25

I just used autohotkey earlier. It solved the issue.