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
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
I'm writing a .bat file to launch two programs, not having success so far. I've followed the guide here.
#echo off
cd "D:\CRCR 0.4.0\"
start "" "D:\CRCR 0.4.0\Chernobyl Relay Chat Rebirth.exe"
cd "D:\MO2\"
start "" "D:\MO2\ModOrganizer.exe moshortcut://:Anomaly Launcher"
exit
Whenever I try to launch the batch file, it tells me "Windows cannot find 'D:\MO2\ModOrganizer.exe "moshortcut://:Anomaly Launcher'. Make sure you've typed the name correctly, then try again."
I've tried removing 'start' from those lines, removing quotations from the cd lines, etc. How can I get this working?
You probably want to pass moshortcut://:Anomaly Launcher as a parameter.
In that case you should also separate the string:
start "" "D:\MO2\ModOrganizer.exe" "moshortcut://:Anomaly Launcher"
Otherwise Windows will interpret the path as D:\MO2\ModOrganizer.exe moshortcut://:Anomaly Launcher not D:\MO2\ModOrganizer.exe and assume that the entire string is part of the path.
I'm having a weird problem when i try to open multiple files in geany with a batch script.
The script is simple going in the folders i gave him as a list, and in each folder it'll open the Makefile here with geany. That is working; however, it'll first open the first Makefile, and then wait until i close the window to open the second one, and so on.
It'll open the next Makefile in another tab, so at the end i still have all my makefiles opened, but i need to close the window between each one and i have a lot to open (that's why i made a script -_- )
Has anyone an idea on how to correct this weird behavior?
I made it in Linux with geany: it works well.
I made it in Windows with notepad: it works well.
But windows with geany doesn't work as i want it to do.
I've also tried using the command start, but it'll ask me with which prog i want to open the files and then do nothing at all.
Here is my script, a bit simplified:
rem set prog="C:\Program Files\Notepad++\notepad++.exe
set prog="C:\Program Files\Geany\bin\geany.exe
set FOLDERLIST="Some Folders Names Separate ByASpace"
for /d %%C in (%FOLDERLIST%) do (
cd %%~C
%prog% Makefile
cd ..
)
So i want it to open all the files at once, without having to close the window between each. As you can see i have a rem line with notepad as prog, and this one is working as expected; geany isn't. But again, i made it in Linux with geany and it does open all files at once.
I found a working answer within this question : SuperUser: Execute command line in background
So, i've found out that, when geany is open and i launch my batch script, it works perfectly. Then i tried to open geany in the batch script before opening all files, but it didn't work. Then, with some advice, i tried to open it like a deamon. And that's how the previously cited answer helped.
Here is the result:
rem set prog="C:\Program Files\Notepad++\notepad++.exe
set prog="C:\Program Files\Geany\bin\geany.exe
set FOLDERLIST="Some Folders Names Separate ByASpace"
for /d %%C in (%FOLDERLIST%) do (
cd %%~C
start "" %prog% Makefile
cd ..
)
It seems that start "" launch the file in the background and so let the script going on and open the others files.
PS: Note that start /B without the "", also given as an answer, does not work for me since it's asking me with which prog i want to open the files.
I am a new programmer, i have created a batch file to open a website but i want that batch file to run when the computer starts.
Here's the code:
#echo off
:top
start iexplore.exe http://www.website.com
timeout 3
goto top
While i do think Arescet's answer will work, i am more in favor of using Windows' Task Scheduler.
Simply create a new task :
Assign it's trigger to be At Startup :
and add a new action to Start a program giving it the path to your batch file:
I believe this is a cleaner approach which also provides you with logging and history should you decide to do more things in your batch file later on
Type run into windows search, type shell:startup in the prompt, press enter, Then, create a shortcut of your program, and move the shortcut into the startUp folder.
On note of your code, the start command should have a blank title as "", and quotes around the application name and parameters passed, like:
start "" "iexplore.exe" "http://www.website.com"
I currently have a Windows batch file that runs an .exe file that uses a text file. I am trying to have the Windows batch file run the .exe file multiple times. This, however, requires the use of the same text files to read from. The command prompt gives me the error that the ".txt could not be opened" (I assume from this that it is already open.)
I am trying to see if there is a way in a .bat file to system call to kill that specific text file. The suggestions I see online are to use 'taskkill notepad.exe', but that returns "invalid argument" because the program doesn't open Notepad to use the text file.
Any suggestions would be appreciated.
It sounds like your existing script fails because the first instance of the exe is still open when the second instance starts.
One thing worth trying (and this depends on the nature of the application you are invoking) is to start the executable using the START /WAIT /B ... command. This makes the command interpreter wait for the program to exit before it moves onto the next command, so as long as nothing else is locking the text files you should be OK to move onto the next command.
I have a VBScript that is supposed to run a .bat or .vbs file, but it doesn't work!
It comes up with an error saying that the file could not be found, whether i put in a file path or not (it shouldn't matter anyway I think because it's in the same directory).
So my question is, how do I start a .bat file (or even better, a .vbs file) from within a VBScript?
The relevant code is bellow:
'*******This is the start of my open command that doesn't work*******
Do
If Hour(Now) >= 9 And Hour(Now) <= 18 And Minute(Now) = 34 And Second(Now) = 59 Then
Dim shell
Set shell = CreateObject("WScript.Shell")
shell.Run "F:\\EAS\Volume Up.vbs"
Set shell = Nothing
MsgBox "My De-bug Message Box which doesn' even get to open"
WScript.Sleep 2000
Set WshShell = CreateObject("WScript.Shell")
music = "C:\...\MYFILE.wav"
WshShell.Run "wmplayer """ & music & """", 0, True
WScript.Quit 1
Else
'*******This is the end*******
So what am I doing wrong? Is it the wrong way to open it? What should I put instead?
It would be good to see the contents of the .BAT File.
Your code seems fine as I am able to run the below script on my machine:
dim shell
set shell=createobject("wscript.shell")
shell.run "tester.bat"
You may not see what the .BAT File is doing as it happens so quickly, as a tester add the following command to the end of your .BAT Script:
pause
Then you will see the command prompt open. As per my VB code above, the .BAT file contents are below:
#echo OFF
#echo %time%
pause
This will show you the current time and then pause, leaving the command prompt open. Give this a go as a tester as it works fine for me.
putting triple quotes (as suggested by ToThePoint) around the path solved my vbs file error, where it was failed to find the file on specified path as file path was having spaces, like
D:\Main\My text Files\abc.txt.
thanks :)
The only thing i can think of is that it must be a typo in the file name.
Can you ensure the file name is spelled correct?
Or else please post the exact error you get.