2

I'm trying to modify the work of a predecessor to improve our workflow. He used a shortcut to a *.bat file and *.exe to configure then start our heavily controlled engineering software. This works great for starting the program, but it means that we can't set the software as the default program to open the file type. This means we always have to open files through the engineering software's GUI, which is lacking in sorting and searching capabilities (critical in folders with thousands of engineering parts).

So currently, the shortcut goes to: %Sharedrive1%\bin\licenseconfig.bat engrCAD.exe

I figured maybe starting engrCAD.exe from the .bat would allow me to use the .bat as a default editor by creating a .bat ConfigNLaunchEngrCAD.bat which has the contents of the original .bat plus start "" engrCAD.exe to the end of the .bat file. This worked in opening the program straight from the .bat, but still goes nowhere when I try to open a file in engrCAD through ConfigNLaunchEngrCAD.bat.

I think what I need to do is make the batch script able to take the file name as a parameter and pass it to the CAD software. But I can't find how to implement that. Is it a parameter I can add to the start command to accept the file name and directory selected? Or am I supposed to use a different command all together to accomplish this?

Much obliged, friends.

EDIT

I'm having trouble seeing the similarity with the other question. I'm looking for a way to run an exe after a .bat configuration through windows that will allow it to be set as a default program for a specific file type. The other post has similarities in the keywords "pass parameters" but little else in common. If I am wrong, I'm sorry, but I may need a little more help to see how the other solution is applicable to this situation.

This question is more similar, but instead of inputing the file name in cmd prompt, I want it to be able to get the file path from me opening the file in windows with the .bat as the default program.

5
  • When you double click a file to be opened by the default program, the program is run with the default executable, and the filename of the file to be opened is passed as parameter. From there, you apply what is similar in the other post Jul 6, 2017 at 22:13
  • So something like this? @ECHO OFF SET var1=%1 engrCAD.exe %var1%
    – Ted
    Jul 6, 2017 at 22:17
  • @fernando.reyes That worked for dragging the file onto the .bat to run it! Thanks! But it still doesn't work for the .bat as the default program, any suggestions for how that could be accomplished? Would it help if I converted the .bat to an .exe?
    – Ted
    Jul 6, 2017 at 22:41
  • This one may be helpful: superuser.com/questions/136133/… Jul 6, 2017 at 22:43
  • @fernando.reyes It's solved! Thanks, your original link was indeed very helpful. The fact the file location is passed as a parameter to the .bat was opaque to me. After your initial comments, drag and drop worked. And on a hunch, adding an additional variable to save and pass a 2nd parameter somehow allows the opening by file association.
    – Ted
    Jul 6, 2017 at 23:52

2 Answers 2

2

I did something similar at my office, we also have a legacy batch file handling license distribution for our software. Depending on how many file types you're dealing with and whether or not you use them in other programs, this solution might work for you. For the record I had never even heard of these CMD tools, but I'm super happy I know about them now.

Here's the plaintext of the answer I found, link is below:

Use Ftype & Assoc to fix this (and it is scriptable).

Use Assoc to get the filetype

>Assoc .txt

gives you:

.txt = txtfile

Then

>Ftype txtfile=C:\Program Files (x86)\Notepad++\notepad++.exe %1

Once you know the file type you can use Ftype to associate it with an action.

This would work for .php files (just plop them in a batch file)

Assoc .php=phpfile
Ftype phpfile="C:\Program Files (x86)\Notepad++\notepad++.exe" %1

And you can copy these lines to add other text-based files as you would like.

Programatically associate file extensions with application on Windows

1
  • Thanks! Although, hmm... didn't seem to work for me. My problem isn't that I can't associate the file type to the .bat file, it's that the .bat file doesn't open them correctly. After I added %1 after Start "" engrCAD.exe, I can drag the file and drop it into the .bat to run engrCAD.exe and open the file. But somehow, when windows opens the file (with the .bat) from default program association, all I get is a cmd prompt opened to the directory of the file.
    – Ted
    Jul 6, 2017 at 23:39
0

Haha, I've solved it! I still have no idea what I'm doing, but here's what I did after much trial and error:

At the beginning of the .bat, I added: Set var1=%1 Set var2=%2

At the end of the .bat, I changed the `Start "" engrCAD.exe' to remove the Start and just run the .exe: engrCAD.exe %var1% %var2%

I believe drag and drop worked after I had added var1 because the file location and name were the first parameter passed to the .exe. Apparently, when opening the file via default program association, the filename/location are not the first parameter? So, adding var2 made it work for both cases.

Anybody who actually knows what is going on.... feel free to comment and correct my interpretation.

Not the answer you're looking for? Browse other questions tagged .