Create script to run program by passing only part of the name

Asked

Viewed 10,500 times

1

I created a small script (.bat) for the installation of several programs silently.

Over time the programs keep updating requiring me to edit the code to put the version number of the program.

Doubt: It would be possible to tell the CMD that regardless of the end of the program name it can locate this program and install?

Example of how it is.

start cmd /C "Winrar 5.40 (x64)" /S
start cmd /C "Chrome 56" /silent /install
start cmd /C "Firefox 52.0 (x64)" -ms

Example of how I wanted it to be. (Locate independent of the end of the main name).

start cmd /C "Winrar *" /S
start cmd /C "Chrome *" /silent /install
start cmd /C "Firefox *" -ms

I studied SQL and when you need to say everything we use *.

I thought I could use * to do the same at CMD but this does not apply because every language is a situation.

  • 1

    Are you making a script for this or will make manual?

  • 1

    Did I get it wrong or does he need help creating a batch script? I don’t understand why it’s outside the scope.

  • 1

    Junior, try [Dit] your question and explain better what you need to do and where the difficulty is. I could understand the part of ignoring the number, but there are still details to imagine where the name will come from, what the criteria to know what to do, and several other points. If the issue makes the doubt clear, and is really within the scope of the site, it can be reopened.

  • I updated the text I hope it helps clarify.

  • 1

    @Bacco considered reopening now?

  • 1

    @Murillogoulart needs four more votes to reopen besides mine. There are still some things that could be better explained, for example, if you have 2 executables with the same start in the same directory, what the criteria, etc.

  • 1

    @Bacco I got it. I was only in doubt if the people who voted to close saw the issue.

  • 1

    @Murillogoulart does not need to be the same staff. Anyone with enough score sees the issue in the analysis queue. Any 5 votes open.

  • Ola Murillo all right I was looking for exactly this bat I would only need if you could help me in relation to it, as I do so that it tamben run a file (msi) create a bat only and that when put it in a folder with program . exe it will run as tamben if that same bat I put in a folder with a program . msi ele tamben execute e no mode de administrador Desde de ja muito obrigo e espera retorno At: James

Show 4 more comments

1 answer

1


Save the content below as exec.bat:

@echo off
    setlocal
    set EXECUTAVEL=
    for %%i in (%1*.exe) do set EXECUTAVEL=%%i
    if /i not "%EXECUTAVEL%"=="" (
       echo Executando "%EXECUTAVEL%"...
       call "%EXECUTAVEL%"
    )
    endlocal

Run in the current directory of the executable:

exec Chrome
  • On line 4 I edited and put (Firefox%1*.exe). When you run the line -> call %EXECUTABLE% CMD terminates even if you display the full name of the program after activating echo to on.

  • 1

    The script is ready, you should not edit. Why not run? exec exec Firefox?

  • CMD does not understand what is exec Firefox...

  • 1

    The batch must be in this folder. It is the same as running exec.bat Firefox, you understand?

  • CMD is displaying -> set EXECUTABLE=Firefox 52.0 (x64). exe and then closes. OBS: I left the settings you submitted.

  • 1

    Parentheses is special character. I adjusted the batch to consider this.

  • 1
Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.