Jump to content
Macro Express Forums

Create Macro From A Batch File Or Script?


Recommended Posts



I was wondering it it was possible to create/define a new macro purely using some kind of batch script?.


ie. Create a brand new macro from 'outside' of macro express, which then appears as an enabled saved macro command as per normal.



Link to comment
Share on other sites

You can create your macro as a text file outside macro express, as long as the text file has the same syntax as you would see if you viewed a macro through the External Editor.


You then create a very short and simple macro within macro express. It might need only a single macro command-- load macro text file-- which reads in your external text file and runs it like a macro. (When I did something similar, I needed a couple of extra commands in this short and simple macro, just to set text variables to equal the path's to my external text files, since I wanted to make it easy to change those pass when the macro was distributed to others.)


You say you want to run the macro on a schedule. As far as I know, you cannot set the schedule in the external text file. You have to assign the schedule within macro express by setting the schedule for the short and simple macro I mentioned above.


There might be ways to have one macro set or change the schedule assigned to a different macro, but I don't know how that would be done.

Link to comment
Share on other sites

I have no idea what you are trying to do but in my experience I've always been able to make ME do what I need by running it in the macro. IOW no having to create special macros for each case. It just sounds to me like you're not taking advantage of some of the programming and logic capabilities of ME and subsequently making life a lot more difficult than it has to be. You might consider sharing with us why you think you need to take this approach. Often I have found that when someone finds an apparent inadequacy in ME it's often because they are approaching the problem wrong to begin with.

Link to comment
Share on other sites

Basically I am trying to use ME instead of the built in schtasks function in Windows itself.

(ie. it's the console version to the snap in 'Task Scheduler')


What it allows you to do is define sheduling via batch script, so you can define a task, remove a task, edit a task etc, but do all of these things from the command line/script, without need of actually launching the windows task scheduler.


I was wondering if I could form similar functionality using ME, by doing as you suggest and forming the text structure as macro editor does.

However, it seems from your post, that the scheduling is handled by the ME engine itself, so this may not be possible.


I guess the next best thing is to just use ME to create the batch scripts that I can then feed to the scheduler console version.


Thank you very much for your input, it's really appreciated!.

ie. One idea sparks another... and so on and so on.



Link to comment
Share on other sites

I see where you're going. OK, a couple of limitations. With qualification ME needs to be running to launch macros on a schedule. Also ME needs to have an active session in order to run. IOW it can’t run as a service. And that session doesn’t need to be a console session. If you’re using ME for more administrative tasks and are not interacting with the GUI of an application it will run just fine in an RDP session or even a locked console session. So if you want to use ME you need to leave a user logged in. Now the qualification is that ME or MXEs can be run from the scheduler itself. This can be very handy, let me tell you. So before we go any further you have to ask yourself, “Do I feel lucky? Well, do ya, punk?” Sorry, that always jumps to the front of my brain. I mean you have to ask yourself if you are willing to have an open session to let ME do its thing. I’m guessing you do if you’re considering it at all.


Another handy thing is a little utility they have called MEProc. How it works is to have ME running but use the MEProc.exe to launch macros in ME without having to re-launch ME itself. I’m not sure how this would fit in for you but many find this very useful.


If you’re just running a bunch of different scripts you can do that right from ME and you can use ME’s logic and such to control how and when these things. For instance you could have it check a folder for new files and if there are any do something with it. And let’s say you use part of the file name for something in the script. Well just stick a string var in the script and set that var using ME from within ME. For instance if it were a user account name you could parse that out and change something with the users permissions with a script.


Personally I am not much of a scripter but I will raid one from someone else every once in a while or I might even use a good old batch file. How I do these using ME is to have ME look up something in the registry or wherever and come up with some vars and then contrsuct a batch file or script using ME and write it to disk. I then have ME run that scrtipt and delete it when it’s done. You can also redirect the output of the script to a results file you can suck into a ME var to check and see if it worked OK or log the results.


For instance I just finished a surprisingly simple script for xcacls which modified NTFS permissions. Now xcacls can do everything from a command line using switches so I didn’t need to write it to a file to run but I did log the results to a file. What the macro did was to plow thu nearly 15,000 customer files explicitly setting additional permissions. This was real simple using a twice nested repeat with folder routine in ME. Simplified what I did was to fire the xcacls command using the folder name I got from one of the “repeat with Folder” commands to add a changing path. Each time it fired I waited for the log file to be ready, sucked it into ME, and checked that it succeeded. Once satisfied it logged the results to a file and moved to the next one. Even if I get failures I can later use that log file to make fixes.


There are other guys here that do a lot more of that sort of stuff that could possibly give better advice on how best to do this but just know it can probably be done if you’re considering ME at all. But it sounds to me that if you’re thinking of creating ME macro files form a script you’re coming at it from the wrong end and need to take a look at how you can use variables to do what you need from one master macro file. Do you have any examples of a specific task you want to do?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...