run an exe for self changing name directory batch file - batch-file

i want to create a portable roblox but these bothers me
i am not so good at batch file but how to i run these exe under these directory i mean
if roblox has an update the "version-3bxxxxxxxx" will change and i cannot run the exe anymore
start "" "C:\Program Files (x86)\Roblox\Versions\version-3b33190189084158\RobloxPlayerLauncher.exe" -app
start "" "C:\Program Files (x86)\Roblox\Versions\version-3b33190189084158\RobloxPlayerLauncher.exe" -app
i try to search on the internet give nothing more =(

I hope you found the help you needed by now, sad no one responded after all this time. This is not as elegant, but I had the same issue and I did this as my solution:
cd\Progra~2\Roblox\Versions\version-* <-just need a "*" wildcard there
start RobloxPlayerLauncher.exe -app
Hope this helps others that want to run a batch file for programs like Discord and Roblox etc. as their directory names always change with updates.... The practice is annoying and I wish devs would consider end users setups.

rEd2k's answer is fine for use directly on the command line. With a batch script, you can automate it.
Search for the exact folder name with a for /d loop and use the found folder as working folder with the start command:
for /d %%a in ("C:\Program Files (x86)\Roblox\Versions\version-*") do set "rootdir=%%a"
start /d "%rootdir%" RobloxPlayerLauncher.exe -app
NOTE: if there is more than one matching folder (versions), rootdir will contain the last found folder (by string sorting on NTFS), which is probably good enough.

Related

make a dir or find command follow shortcuts

I'm currently trying to set up a batch file or something similar to run a search through a series of different file shares at my workplace.
I'm fairly new with CMD, but have managed to get what I'm looking for in one instance, and I'm now looking to apply that through several different files at once.
C:\Users\My Username> dir c:\Users\My Username\documents -path \appdata -prune -o *.xml /b /s >c:\users\My Username\documents\Filename
Above is the code I'm using currently to source from one file, omitting the Appdata file, as that was being returned & I didn't want its contents in the output.
However, this code above is simply a test that I've used; my end goal is to apply that to several different files accessible through the company, so for example,
DriveLetter:\SiteLocationFolder\SpecificFileShare\> dir DL:\SLF\SFS\ -path \UselessFolder -prune -o *xml /b /s >DL:\SLF\FileShareReportsFolder\
For the sake of anonymity, I've substituted in placeholder names in the file path.
My issue exists in that, in the Site Location Folder, all of the Specific File Shares are accessed through shortcuts, and I was wondering whether there was a string to allow CMD to run the dir through these shortcuts, or if I would instead have to run the batch file for each different Specific File Share?
The cmd.exe shell DIR command will not follow shortcuts in the same way as a link. If you must use Windows shortcuts, you might need to look into https://www.computerhope.com/forum/index.php?topic=80659.0
Another way would be to make links using the Windows mklink command. Use mklink /? to read about it. Search the net to learn the differences between links and junctions.

How to mention C:\Program Files in batchfile

I need to invoke an exe file in C:\Program Files directory from a batch file.How can we mention the directory name "Program Files" in batch file.I am getting error like C:\Program not found.
I believe that % or ~ needs to be added in between but couldn't get it.Kindly assist.
Surround the script call with "", generally it's good practices to do so with filepath.
"C:\Program Files"
Although for this particular name you probably should use environment variable like this :
"%ProgramFiles%\batch.cmd"
or for 32 bits program on 64 bit windows :
"%ProgramFiles(x86)%\batch.cmd"
On my pc I need to do the following:
#echo off
start C:\"Program Files (x86)\VirtualDJ\virtualdj_pro.exe"
start C:\toolbetech\TBETECH\"Your Toolbar.exe"
exit
Now that bash is out for windows 10, if you want to access program files from bash, you can do it like so: cd /mnt/c/Program\ Files.
I use in my batch files - c:\progra~2\ instead of C:\Program Files (x86)\ and it works.
I had a similar issue as you, although I was trying to use start to open Chrome and using the file path. I used only start chrome.exe and it opened just fine. You may want to try to do the same with exe file. Using the file path may be unnecessary.
Here are some examples (using the file name you gave in a comment on another answer):
Instead of C:\Program^ Files\temp.exe you can try temp.exe.
Instead of start C:\Program^ Files\temp.exe you can try start
temp.exe
use this as somethink
"C:/Program Files (x86)/Nox/bin/nox_adb" install -r app.apk
where
"path_to_executable" commands_argument
Interestingly with variables ,this worked for me ...
SET "VESTADIR=\\%TARGET%\C$\"Program Files (x86)"\Cassidian\VESTA"
While createting the bat file, you can easly avoid the space. If you want to mentioned "program files "folder in batch file.
Do following steps:
1. Type c: then press enter
2. cd program files
3. cd "choose your own folder name"
then continue as you wish.
This way you can create batch file and you can mention program files folder.

I am trying to start an office program on a flash drive with a batch file

I am putting Kingsoft office on my flash drive, and I want to use a batch file to start the applications because the paths are not easily accessible, I cannon create a .lnk file because the path varies by computer because it may be plugged into a different port. Here is my batch file code, could somebody give some suggestions on how to make this work. Thanks in advance...
set "path=%~dp0"
start %path%office6\wpp.exe
The second line is the problem, the program won't start the program. Thanks!
cd /d "%~dp0"
start "" /b wpp.exe
I think some of the directory names in %path% contain spaces and since %path% is not enclosed within ""( double quotes), the script is unable to find the exe .
You may also want to include a log file so that it becomes easier to debug in case of any errors.
Try this:
set baseFolder=%~dp0
start "%baseFolder%office6\wpp.exe" > "%baseFolder%batchRunLog.log"

using the dir command writing a batch proccess

Im writing a batch file for work. basically my command right now navigates to a file path, then prints out the contents of the folder with the dir command.
Without giving the specifics away of what i am trying to print out here is the code im using
CD C:\Some folder\some folder2\some folder 3\some folder 4
DIR
now in "some folder4" there are 3 files. If i use the code
CD C:\Some folder\some folder2\some folder 3
DIR
It prints out fine that there is a folder "some folder4" in "Some Folder3", but as soon as i change the directory into the "some folder4" folder it says file not found instead of showing me the 3 files that are in it.
Any advice as to what would be causing this
I think we need more specifics of what you're doing here (you're going to have to give away a bit more), but one thing you should definitely look at is the for /d command instead of DIR.
You know you can use a filespec with the DIR (or for) command right? Changing the directory isn't really the best choice - especially since drive and relative paths are assumptions. [cd h:\test\ doesn't switch drive if you're on c:\, but dir h:\test\ will work no matter what drive you're on]
If your folders have spaces in them, it could be you need to escape the folder name with quotes (cd "some folder4").

Prevent overwriting a file using cmd if exist

I am currently writing a .bat batch file that executes an installation file. Before it runs the installation file I check to see if the directory exists to avoid re-installing the application.
I do this by using a If Not Exist filename statement. If the installed file doesn't exist, I then execute the installation file.
For some reason, when I test it with the application where it has been installed already, it is still trying to reinstall the application over it.
Here is a snippet of my code:
cd "C:\Documents and Settings\John\Start Menu\Programs\"
pause
If NOT exist "Software Folder"\ (
start \\filer\repo\lab\"software"\"myapp"\setup.exe
pause
)
Where SoftwareFolder is a subdirectory of "C:\Documents and Settings\John\Start Menu\Programs\". I am checking to see if it exists in my Programs folder.
I know nothing is wrong with my start command. I have a feeling something is wrong with my beginning CD command or one of its parameters.
Thanks a lot, guys!
Use the FULL path to the folder in your If Not Exist code. Then you won't even have to CD anymore:
If Not Exist "C:\Documents and Settings\John\Start Menu\Programs\SoftWareFolder\"
I noticed some issues with this that might be useful for someone just starting, or a somewhat inexperienced user, to know. First...
CD /D "C:\Documents and Settings\%username%\Start Menu\Programs\"
two things one is that a /D after the CD may prove to be useful in making sure the directory is changed but it's not really necessary, second, if you are going to pass this from user to user you have to add, instead of your name, the code %username%, this makes the code usable on any computer, as long as they have your setup.exe file in the same location as you do on your computer. of course making sure of that is more difficult.
also...
start \\filer\repo\lab\"software"\"myapp"\setup.exe
the start code here, can be set up like that, but the correct syntax is
start "\\filter\repo\lab\software\myapp\" setup.exe
This will run: setup.exe, located in: \filter\repo\lab...etc.\
As in the answer of Escobar Ceaser, I suggest to use quotes arround the whole path. It's the common way to wrap the whole path in "", not only separate directory names within the path.
I had a similar issue that it didn't work for me. But it was no option to use "" within the path for separate directory names because the path contained environment variables, which theirself cover more than one directory hierarchies. The conclusion was that I missed the space between the closing " and the (
The correct version, with the space before the bracket, would be
If NOT exist "C:\Documents and Settings\John\Start Menu\Programs\Software Folder" (
start "\\filer\repo\lab\software\myapp\setup.exe"
pause
)

Resources