BATCH interactions with opened .exe

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Mado91
Posts: 13
Joined: 16 Mar 2019 08:03

BATCH interactions with opened .exe

#1 Post by Mado91 » 16 Mar 2019 08:15

Hi everyone,
I'm a self-taught (nice way to mean "noob") programmer and that's my first approach to DOS comands and .bat files. I've already written a couple of .bat that can do basic things with inputs, so now I wonder: is it possible to make a .bat program opens an .exe and interact with it? For example, can I write a .bat that can open a .xlsm file and make it execute a macro written in VBA?
Thanks

aGerman
Expert
Posts: 3625
Joined: 22 Jan 2010 18:01
Location: Germany

Re: BATCH interactions with opened .exe

#2 Post by aGerman » 16 Mar 2019 13:03

Short answer: No.

Long answer:
Batch cannot interact with graphical user interfaces.
For your example that means you can open an .xlsm file but you can't make it execute a certain macro. That's the responsibility of Excel. You can write a macro that gets automatically executed if the file was opened. But again, you have to specify that in the .xlsm file itself.

Steffen

Mado91
Posts: 13
Joined: 16 Mar 2019 08:03

Re: BATCH interactions with opened .exe

#3 Post by Mado91 » 17 Mar 2019 04:09

Hi, thanks for the answer. So now I wonder... what level of "freedom" can I have to interact with non-bat files? For example, I know that DOS can create and edit txt files, or even edit a previously existing file. I made experiments using the following code:

Code: Select all

set /P input=
echo %input% >> output.txt
or even

Code: Select all

set /P input=
echo %input% >> output.xls
If I can read and edit the content of a file with different extensions containing text, can't I, for exemple, edit a .xlsm file containing macros just with DOS? Maybe I can't directly interact with the macros, but there's a way to write them?

aGerman
Expert
Posts: 3625
Joined: 22 Jan 2010 18:01
Location: Germany

Re: BATCH interactions with opened .exe

#4 Post by aGerman » 17 Mar 2019 04:54

Most of the commands can only handle plain text. They see what you would see if you open a file in a text editor. If you open a .xlsm file in a text editor you won't recognize anything of the content you see if you opened it in Excel. So again the answer is no.

Steffen

ShadowThief
Expert
Posts: 891
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: BATCH interactions with opened .exe

#5 Post by ShadowThief » 17 Mar 2019 11:44

Technically yes, since xlsx/xlsm/xls* files are nothing more than an archive of XML files, but the way to do it is super convoluted since you would have to extract the files, update the XML, and repack the files all using pure batch.

It can be done, but you really, really, really don't want to do this.

Mado91
Posts: 13
Joined: 16 Mar 2019 08:03

Re: BATCH interactions with opened .exe

#6 Post by Mado91 » 17 Mar 2019 11:56

Got it, thanks everyone!
anyway, even if I really, really, really wanted to do it, I wouldn't know how :lol:

Post Reply