Home > database >  My BAT file does not execute my executable file
My BAT file does not execute my executable file

Time:01-02

I have a code witch I want to starts when windows starts so I added bat file in

C:\Users\Admin\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

directory and my bat file is like:

start "random title" "C:\test\dist\test.exe"

this code works when I use it in cmd but in bat it only shows terminal for like 0.01 second then it close itself without run my code I have added cmd.exe at the end of my code just to see the error log but did not worked then tried pause cmd-k and other solutions

any idea would be very usefull

also I am searching this for days so I guess I have checked every source I could find so this question seems like dublicate but other questions did not solved my problem

CodePudding user response:

At the end of the day I ended up with creating a shortcut as Compo said here is my code:

path = os.path.join(bat_path, 'windowsStartup.lnk')
target = file_path

shell = win32com.client.Dispatch("WScript.Shell")
shortcut = shell.CreateShortCut(path)
shortcut.Targetpath = target
shortcut.WindowStyle = 1
shortcut.save()
  • Related