Trying to run a basic .bat file on my work machine. I have a file named chrome.bat that contains only the line start chrome. When I enter start chrome into CMD or PowerShell, it opens a new window of Chrome as one would expect. When I click on the .bat file, however, new instances of CMD are continuously created, no Chrome window is opened, and I have to hold CTRL-C until the process is killed.
Any insight?
Figured it out. The problem is that I named the file with the same name as the command. Renaming the file to blah.bat works just fine.
Related
I have the following cmd command:
C:\Users\spidey\AppData\Local\Programs\Python\Python39\python C:\Users\spidey\Documents\sleepScript\textdocument.py
Inside a .bat file. When I double click and run it, it runs well but when I try to right click and run as administrator it just opens the window and closes adruptly without completing the execution.
The end result of the command is a text file which is created in first case but not when I try to run it as administrator.
The reason for this to run as adminstrator is because I will be running it on cloud and so there it runs as administrator.
Here are the content of textdocument.py:
import datetime
file = open('read.txt', 'w')
file.write('Executed # ' + str(datetime.datetime.now()))
file.close()
Here is another update:
Tried to create a shortcut and setup it's advanced property as run as administrator. But that doesn't work as well.
After doing this, I tried to run the .bat file again as administrator but no effect.
As suggested in the comments, I shifted all the files to C: drive so that it's accesible to everyone. But unfortunately that didn't work as well window just opens and aprubtly closes without giving the end result. On the other hand normal running works here as well.
Here is the command:
C:\Python\Python39\python C:\uiPath\textdocument.py
After a long debugging, I realized that the command was actually running correctly. It's all that it was saving the file into the other default directory after adding in my python script:
os.chdir(path)
Where path is the path where I wanted it to store. Whereas in case of double clicking and running it, by default that path was set to the path where the file was located in.
The problem got fixed. Thank you everyone for the help!
i want to write a script that when excecuted it will search for a specific file or program and if it's not open for the code to open that file. I'm in school bored and want to have my e-textbook automatically open on logon(i figured out running the script from login) when its not running
I do not have a code for you but I do have a way for you to open any program and or file from the startup.
Open RUN --- By holding down the windows key and pressing R.
Type the following in to RUN shell:startup
It will open a folder.
Make a shortcut of the file/program and move it into the opened folder.
That is it next time you switch your PC on it will run it automatically.
I am trying to open a .chm file from a batch file.
The batch file has only this text in it :
echo off
start "S:\G.T.T\GTT-Vandemecum\Help Danny\GTT.chm"
If I run the batch file, the commandline opens but nothing further happens.
If I copy paste S:\G.T.T\GTT-Vandemecum\Help Danny\GTT.chm in start menu/run then it does works.
If I make a shortcut with target "S:\G.T.T\GTT-Vandemecum\Help Danny\GTT.chm" then it also works.
So the command works everywhere, except from a batch file.
What am I doing wrong here ?
It might also be important to know that when I start it from the shortcut, or start menu/runI always get a dialog
We can't verify who created this file. Are you sure you want to open this file ?
I am using Windows 7
EDIT
My problem is not the dialog, my problem is that nothing happens when I open the chm file from a batch file
The Start command is probably seeing your doublequoted string as a title, enter Start /? at the command prompt for its usage information.
Try adding an empty title first:
#Echo Off
Start "" "S:\G.T.T\GTT-Vandemecum\Help Danny\GTT.chm"
I have a .exe file converted from a .jar.
It is a command based application, so I have to start it with a batch script. Here is the batch script:
#echo off
cd C:\desktop\plant-text-adventure-win
start planttextadventure
pause
When I double click on the batch script, this happens: Windows could not find 'planttextadventure'. Please confirm if you have input the correct name and retry.
I don't know what is happening, I have no idea about cmd as I use Mac, but I can confirm I have an executable called planttextadventure.exe in a folder called plant-text-adventure-win.
You should test your batch file by executing it within a shell.
Simply enter within the start menu the command cmd to open up a shell. Within this black box you could now simply enter the commands from your batch script and lookout for some error message.
If you look at your script I would guess that the cd command (to change the current directory) is not correct. Maybe you should replace it with
cd %USERPROFILE%\Desktop\plant-text-adventure-win
because the desktop folder is on a default installation not directly under the root drive but within the user profile available.
Another solution to get this thing to work, is by opening the windows explorer, going to the .exe file you wish to execute and drag & drop the .exe file with a right mouse click onto the desktop.
Then a context menu appears and you select the option Create shortcut here.
::Checks if there is a JRE installed
start "%USERPROFILE%\Downloads\ConfCompiler\Tools\CheckJre.exe"
When I copy and paste the file location above into Windows Explorer it works fine. But the program does not run from the batch file I have created.
The purpose of CheckJre.exe is to create new keys inside of HKEY_CURRENT_USER.
The keys are created when I simply run it from Windows Explorer. But the keys are NOT created when running it from the batch file. The batch file just results in displaying a command prompt window with showing CheckJre.exe with full path in title bar.
Does anyone have a hint why?
Command start interprets the first double quoted string as title for the command line window to open. For all options of command start enter in a command prompt window either start /? or help start.
You need to explicitly specify a title in your batch file because of the double quoted string to run CheckJre.exe.
Use in batch file:
start "Check JRE" "%USERPROFILE%\Downloads\ConfCompiler\Tools\CheckJre.exe"