A downloadable extension

Download NowName your own price

Quick links: source code · GM Marketplace page

This single-function extension allows to call ShellExecute from GameMaker: Studio and GameMaker Studio 2 games.

The function execute_shell_simple takes up to 4 arguments:

  • path (required)
    The absolute path to whatever you are trying to run - an executable, a text file, a .url, etc.
    If you are not sure how to get the true path to your file, have the game copy it to save directory (game_save_id).
  • args (optional)
    Command-line arguments to pass. Non-executables will generally ignore these.
    If omitted, defaults to "".
  • action (optional)
    What to do with the file, as per lpOperation in MSDN.
    If omitted, defaults to "open".
  • showCmd (optional)
    One or other magic number (such as 6 for SW_MINIMIZE) from the same MSDN page.
    If omitted, defaults to 5 (SW_SHOW).

Examples

Create a text file and open it in default editor:

var _path = game_save_id + "/hi.txt";
var _txt = file_text_open_write(_path);
file_text_write_string(_txt, "Hi! " + date_datetime_string(date_current_datetime()));
file_text_close(_txt);
execute_shell_simple(_path);

Create a text file and open it in Notepad:

var _path = game_save_id + "/hi.txt";
var _txt = file_text_open_write(_path);
file_text_write_string(_txt, "Hi! " + date_datetime_string(date_current_datetime()));
file_text_close(_txt);
var _windir = environment_get_variable("WINDIR");
execute_shell_simple(_windir + "/Notepad.exe", _path);

Create an internet shortcut and open it in default browser:

var _url = "https://yoyogames.com";
var _path = game_save_id + "/shortcut.url";
var _txt = file_text_open_write(_path);
// note: use '' instead of @'' in GMS1
file_text_write_string(_txt, @'[{000214A0-0000-0000-C000-000000000046}]
Prop3=19,11
[InternetShortcut]
IDList=
URL=' + _url);
file_text_close(_txt);
execute_shell_simple(_path);

For more advanced uses, consider Execute Shell or Evaluate Shell by Samuel Venable.

Download

Download NowName your own price

Click download now to get access to the following files:

execute_shell_simple_ext-for-GMS1.gmez 4 kB
Version 1.1
execute_shell_simple_ext-for-GMS2.yymp 7 kB
Version 1.1
execute_shell_simple_ext-for-GMS2.3+.yymps 8 kB
Version 1.1

Development log

Comments

Log in with itch.io to leave a comment.

(+1)

Thank you, this helped to solve a problem I was having with opening URLs. For anyone here to be able to crack open a web link, just do;

execute_shell_simple("https://yourwebsitehere.com");

It would be amazing if there was execute shell for android. Would definitely pay in the marketplace for an android execute shell like function.

Is your intention to open a file or launch another application?

I was thinking about launching an apk file or opening another file as well with a function (script) similar to execute shell.

Could you explain to me how to simply open a webpage with this? in GM 1.4

See the “Create an internet shortcut and open it in default browser:” right in the itch.io page description

Do I have to create the shortcut first? Or can i just run a command to open a webpage?

The snippet creates a shortcut and then opens it, as the title says. Paste it into some keyboard press event and see what happens

(1 edit)

I found if i just used execute_shell_simple("url") it worked :)

Can you make it work for Android?

That requires a complete rewrite and investigating how and whether that could be done on Android, so probably not.

Thanks for this! Really comes in handy. I have however noticed that it doesn't seem to work on some computers.

When I launch my game I'm checking for an update, if there is one I download the updated version to the working_directory. When the .exe is downloaded I run it with your script. Work flawlessly on two of my computers, but for some reason it doesn't on the last one I tried it on 🤔

I don't know if you have any idea why?

Anyways, thanks for making this! 😀

It is possible that your executable gets confiscated by an antivirus program for the duration of scan - try with something simpler like a .txt file first.

i get the execute_shell_simple_raw thing and not the original function, for some reason the examples dont work

I don’t know how you have accomplished this since I checked and both the extension and the sample project have the DLL + GML files.

I'm having the same issue. Downloaded the YYMP, then imported it into my project as a local package. execute_shell shows up as a constant and execute_shell_simple_raw shows up as a function. Nothing happens when running execute_shell_simple_raw

I released a new version that renames the extension to not be the same name as its main function

(+1)

Thank you for this! :D

(1 edit)

Hey YAL, love your stuff. (question about transition to Windows 64)

If you are using the new 64-bit Windows runtime, you should be aware that it breaks every single existing DLL. I wouldn’t recommend using it unless you are confident that every extension you use can be updated.

As for my extensions in particular, a quick search shows that I have dozens of ones that use DLLs, and many of them have not been migrated to GMS2 (instead relying on compatibility scripts), so it will take a while to update all of them.

If it is extremely urgent, you may attempt to compile extensions yourself using the source code that is either included with the extension (for paid extensions) or linked on the extension page (for free extensions), though code changes may be required for - argument and return types vary 32-bit to 64-bit for many system functions.

(2 edits)

I'm kind of in a bind. Releasing a large update for my project on the 25th, and the 64x stops some memory allocation issues people were having, but I also don't want to lose your mouse_lock stuff :L

How would I go about compiling it myself, I don't know what the heck I'm doing with extensions?

If this is not something I could realistically do quickly on my own, no worries.

Good stuff

Thank you!