The following command works just great as the only line in a batch file:
start "Google Sync" /belownormal "C:\Program Files\Google\Drive\googledrivesync.exe" /autostart
When I drop that line into msconfig startup tab, however, nothing happens.
So I thought maybe I needed to put in the full path to start.exe. Assuming it was an exe, that is.
So I tried both DIR and WHERE to locate start.* but nothing came up.
So, two 2uestions.
Is start a separate START.EXE executable in W7Pro and if so where is it?
How can I get this line to work inside msconfig?
Before you ask, my underlying purpose is to start Google Backup and Sync in the same way it usually does, but with /BELOWNORMAL priority. I already tried adding /BELOWNORMAL to the line Google was originally using in msconfig, without success. But START does what I want from a batch file and so I assume it would, or should, work via msconfig.
Thanks.
If you want to use commands implemented by Cmd.exe you must invoke Cmd.exe:
cmd /c start "Google Sync" /belownormal "C:\Program Files\Google\Drive\googledrivesync.exe" /autostart
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 want to create a batch file to launch my executable file after it has made some changes to itself.
My batch file is:
START /D "C:\Users\me\AppData\Roaming\Test\Test.exe"
When I run it though I just get a brief console flash and Test.exe doesn't start up.
I've verified the EXE is there in the directory.
I've launched the exe manually to verify it is working as well.
My batch file resides in
C:\Users\admin\AppData\Roaming\run.bat"
There are two issues:
The /D option solely defines the starting or working directory, but not the program to execute.
The start command considers the first quoted argument as the title of the new window. To avoid confusion with other arguments, always provide a window title (that may also be empty).
There are two solutions, which are actually not exactly equivalent:
Remove the /D option, so the current working directory is used:
start "" "C:\Users\me\AppData\Roaming\Test\Test.exe"
Keep the /D option and explicitly provide the new working directory to be used:
start "" /D "C:\Users\me\AppData\Roaming\Test" "Test.exe"
try changing to this
start /d "C:\Users\me\AppData\Roaming\Test" Test.exe
You will see the console flash and your program should startup.
Update
Thanks for #SomethingDark 's suggestion to use the following code.
start "" C:\Users\me\AppData\Roaming\Test\Test.exe
However, the above code will not work if your filename contains space.
Try with the following command.Add it to your batch script.Notice that you have to add double quotes after start keyword if there is/are whitespaces in the path string.
start "" "C:\Users\me\AppData\Roaming\Test\Test.exe"
Enclose any directory names which are longer than one-word into quotation marks. So the following path:
start C:\Program Files\MySQL\MySQL Workbench 8.0 CE\MySQL.exe
Should become something like this:
start C:\"Program Files"\MySQL\"MySQL Workbench 8.0 CE"\MySQL.exe
I am writing a batch file on my Windows 8.1 machine. In one section of my batch file I need to start a command prompt in the "current working directory".
So far, this is what my batch file looks like:
#echo OFF
set WORKING=%cwd%
start cmd.exe /K pushd %WORKING%
exit
Let's say the batch file is located in the folder C:\Temp\Utilities. If I open an explorer window and double click the batch file to run it everything works great. A new command prompt is created in the directory C:\Temp\Utilities. However, if I right-click the batch file and select Run as administrator the working directory is no longer the location of the batch file, it's C:\Windows\System32.
Similarly, if I create a shortcut to the batch file in a different folder (for example. C:\Temp) and repeat the two steps above the results are the same. If I double click the shortcut and run it as a normal user the working directory is what I would expect. (Note, the working directory for the shortcut it's whatever is set for "Start in" of the shortcut properties, not the location of the batch file.) If I right click the shortcut and run it as administrator I again get a command prompt opened to the folder C:\Windows\System32.
I assume this is a "bug" or "feature" (if you want to call it that) in Windows 8.1 and it probably happens because execution environments for programs run as administrator are forced to run in the System32 folder? (I remember with Windows 7 this did not happen so it must be a new feature to Windows 8.)
I found one way to fix the issue and stop the command prompt from starting in C:\Windows\System32. I did this by modifying the following line in the batch file:
set WORKING=%~dp0
Doing it this way sets the working directory to the location of the batch file. With this change, no matter how I run the batch file or the shortcut (administrator or normal) the working directory ends up being the same, C:\Temp\Utilities.
The problem with this solution is I don't want the working directory to always be the location of the batch file. If the batch file is run directly then it's okay but if I run it from a shortcut I need the working directory to be whatever is set in the "Start in" property of that shortcut. For example, if the batch file is located in the folder D:\Temp\Utilities this is what I need to happen regardless of whether I run as administrator or not:
Shortcut Location Start In Property Command Prompt Working Directory
-------------------- ------------------- ------------------------------------------
C:\Temp <undefined> D:\Temp\Utilities
C:\Data\bin C:\Data\bin C:\Data\bin
C:\Data\bin D:\Temp\Utilities D:\Temp\Utilities
What this means is I can't always use %~dp0 to set the working directory in my batch file. What I need is some way for the batch file to know if it was run either directly or by a shortcut. If the batch file is run directly then the working directory is easy to get, it's just the value of %cwd%. If the batch file is run by using a shortcut, I don't know how to get the "Start in" property inside the batch file.
Does anyone know how I can do these two things inside my batch file:
1. Check whether it was run directly or by a shortcut.
2. If run by a shortcut, get the "Start in" property of the shortcut that started it.
Thank you,
Orangu
UPDATE
I found sort-of a "hackish" way to fix the issue. For the shortcut I edited the "Target" field and changed it to the following:
cmd.exe /k pushd "C:\Temp" && "D:\Temp\Utilities\batchfile.bat"
Now the working directory can be obtained by calling %CD% in the batch file and this works for both administrator and normal users. It does not, however, work for the case when I run the batch file directly. I still need to use %~dp0 in that case.
I don't like this solution, however, because it requires me to manually change all shortcuts I make and it also makes the icon look like a cmd prompt icon rather than a batch file.
Have you already considered to not use shortcuts at all?
You could e.g. create a batchfile_exec.bat containing your call
REM optionally do
REM cd /D working_directory
REM if you want to force a special working directory
D:\Temp\Utilities\batchfile.bat
and replace all the shortcuts with batchfile_exec.bat. If you double-click batchfile_exec.bat, the working directory will be the one containing batchfile_exec.bat.
I personally don't like Windows shortcuts that much, because they are hard to handle within a revision control system. As you also noticed, it is very time consuming if you want to modify a lot of them.
By the way: If batchfile.bat was designed/written to be always run from the direcory where it is located, you might also consider to modify batchfile.bat to force that behaviour:
setlocal
cd /D %0\..
REM your original content
endlocal
In %0 the path to the batchfile is stored.
The trick is to assume that %0 is a directory and then to change one level lower based on that directory. With /D also the drive letter is changed correctly.
The cd command doesn't care if %0 is really a directory. In fact %d doesn't even have to exist (%0\dummy\..\.. would also work).
The setlocal command is to have the working directory being restored when batchfile.bat has finished (this would be good if batchfile.bat was called form another batch file).
I noticed that the endlocal command is not really necessary in this context since it is applied implicitly when batchfile.bat finishes.
I have a bunch of batch files which I want to run sequentially. One of them runs an MSI which adds a folder to the PATH. How can I make sure that subsequent batch files will notice this change, without restarting CMD? I'm using Windows Server 2008 R2 x64.
I've tried call, cmd /c and start "", in the hope that starting a new process will work, but it doesn't.
in run-both-scripts.bat
call script1.bat <-- This runs an MSI which modifies the PATH
call script2.bat <-- This relies on the PATH changes which were made by the MSI in script1.bat
To clarify: this is fairly straightforward to reproduce.
Start CMD
Create an environment variable manually, not using setx, to mimic what the MSI does.
Right click on Computer -> Properties -> Advanced System Settings -> Environment variables -> New
Create an environment variable called, say, hello with the value hi there.
In your CMD window, type echo %hello%. You'll get %hello%.
Try cmd /c "echo %hello%. You'll get %hello%.
Try start "" to open a new CMD process; type echo %hello%. You'll get %hello%.
Try start "" echo %hello% to run the command in a new CMD process. You'll get %hello%.
Finally, try manually opening a new CMD window from the Start menu and type echo %hello% from there. You'll see hi there.
So you can see that the only way I've been able to make CMD see the change to the environment variable is by restarting CMD.
Ok, did some research, and found out why the soloutions we've been throwing at you don't work. When you start cmd.exe as an application, it looks at the current environment variables and copies it to memory. When you start cmd in a batch file, it will not look at the environment variables, instead it will look at the variables set in the current batch file, and utilise those. Thats the problem when your storing data on memory. The only way this is possible is if you copy the current environment variables into a text file as memory on a hard disk. Now, the question is how to go about doing this.
After heavy research, the only thing I could find that related to the topic was the use of start /i, however, when I tested this it didn't work. (start /? for more info).
In other words, other the setx, I don't think this is possible with batch.
Mona
I'm using cl in cmd and having to run vcvars32.bat every time I open a cmd window is really a pain in the axx. Can anyone offer a way of running it automatically?
From cmd /?:
If /D was NOT specified on the command line, then when CMD.EXE starts, it
looks for the following REG_SZ/REG_EXPAND_SZ registry variables, and if
either or both are present, they are executed first.
HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun
and/or
HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun
You therefore could add vcvars32.bat to one of those AutoRun registry values to have it executed for every cmd.exe instance (except when /D is explicitly specified, of course).
However, be forewarned that doing this could result in other weird side-effects (for example, it could cause other .bat/.cmd scripts to be run in an environment that they aren't expecting).
A workaround that works for some people is to write a batch file and call it A.BAT and make a.bat launch vcvars32.bat. Put a.bat on the path and then it's a matter of opening the cmd prompt and typing a and enter and voila, you're set!
way old, but the easiest way to do this with, say, a shortcut created on your TaskBar is to modify your shortcut (in %appdata%\microsoft\internet explorer\quick launch\user pinned\taskbar, or thereabouts) so the target is:
%windir%\system32\cmd.exe /k vcvars32.cmd
that'll do exactly what you're looking for. The /k tells it to execute the string but keep the window open (string being your batch file). You can either put vcvars32 somewhere in your path, or specify the whole path to vcvars32.
You can use the script in http://www.alteridem.net/2010/09/02/visual-studio-2010-command-prompt-here to make it so when you right-click a folder in explorer the option shows up. After downloading and extracting the zip file you can modify the .inf to point to the correct path to your particular VS version (and change the displayed name if desired). Note the comment on the page about having to rename the file if you are running 64-bit Windows.