Create an executable file to open a non-executable file

Hello,

How do you create an executable file to open a non-executable file?

I just began using a Corsair K95 RGB keyboard (which includes 18 programmable G-keys) along with its software (CorsairUtilityEngineSetup_2.24.50_release). While assigning macros to the G-keys, I discovered that while the software does allow you to run an executable file (*.exe *.bat *.cmd), there is no option to open a simple non-executable file (eg .txt, .xls, .ahk, .png, etc).

That seemed a bit odd to me but it was confirmed by Corsair tech support so during the conversation I asked about possible workarounds and the response was that I could create an .exe or .cmd file to open the desired non-executable file.

So for example, suppose you want to open the following Excel file:

    C:\Users\UserName\FolderName\FileName.xlsm

How would you create an .exe or .cmd file to do that?

Thanks
WeThotUWasAToadAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Nitin SontakkeDeveloperCommented:
I don't think there is any need to go that far. If you system allows you pass parameter to whatever the command is, there is actually one universal command that you can use on a command prompt and that is "start".

Just type start and filename of any type. This will identify the associate application to the extension of the file you just supplied, then invoke that application and that application will in turn open the file.

So you can have:

start abcd.xlsx
start pqr.pdf
start xyz.docx

....and so on.
1
Joe Winograd, Fellow&MVEDeveloperCommented:
Hi Steve,
Since you're already an AutoHotkey user, you can do it in one line of code:

Run,C:\Users\UserName\FolderName\FileName.xlsm

Open in new window

Put that in a source code file (say, RunExcel.ahk) using your Notepad++ capability that we've discussed in the past, then compile it into an EXE file using the AutoHotkey compiler, as explained in my EE article:
AutoHotkey - Getting Started

Regards, Joe
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
WeThotUWasAToadAuthor Commented:
Thanks for the responses.

Nitin Sontakke
Just type start and filename of any type.

I think it needs to be an actual file rather than a start command.

Joe Winograd, Fellow&MVE
Since you're already an AutoHotkey user, you can do it in one line of code:

Great solution Joe. Thanks for pointing me back to your ahk-getting started article. I either overlooked or had forgotten the compiler part but that's a great option.

From your article:
A standard installation of AutoHotkey also installs a compiler, which converts an AHK source code file into a stand-alone executable (an EXE file).

One question that brings to mind however is the following:

Are the compiler-created exe file and its source ahk file connected? In other words, if, after creating the exe file, changes are made in the ahk file, will the changes sort of automatically flow-through to the exe file or will the two files now be different? Put another way, should a new exe file be created each time changes are made to the ahk file?

Thanks
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Joe Winograd, Fellow&MVEDeveloperCommented:
> Thanks for pointing me back to your ahk-getting started article.

You're welcome, Steve, and thanks back at you for endorsing the article — much appreciated!

> Are the compiler-created exe file and its source ahk file connected?

I wouldn't use the word "connected", but I understand what you're asking, and the answer is yes. The EXE file is actually the AutoHotkey interpreter itself with the script embedded inside the EXE file.

> In other words, if, after creating the exe file, changes are made in the ahk file, will the changes sort of automatically flow-through to the exe file or will the two files now be different?

The two files will now be different. In fact, the EXE is usually on another computer, not on the computer with the AHK source code. Your usage of it is unusual. The most common use is to be able to run an AutoHotkey script on a computer that doesn't have AutoHotkey installed. So, of course, there's no way that a change to the AHK source will "flow through" to the EXE file — you must recompile.

> Put another way, should a new exe file be created each time changes are made to the ahk file?

Exactly!

Regards, Joe
0
tuviCommented:
simpler, put

start C:\Users\UserName\FolderName\FileName.xlsm

Open in new window


in a .cmd file
0
WeThotUWasAToadAuthor Commented:
Thanks
0
Joe Winograd, Fellow&MVEDeveloperCommented:
You're welcome, Steve, happy to help, as always. Regards, Joe
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.