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.

phuclv
  • 30,396
  • 15
  • 136
  • 260
Ted
  • 21

2 Answers2

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

jcam3
  • 246
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.

Ted
  • 21