SRL Archive - Computer Help and Tutorials

How To Make Any Scar Script A Standalone.exe


caused

2009-06-28 23:22:24

(I cant create a Thread in the Tutorial Island, where i want to o_o, and since this topic might be interesing for some of you i'll do it here).

Introduction:
Ok, heres the method i'm using to make my scripts standalone exe files. It will work for any scar script. You will have a nice user-friendly .exe file : D. I'm using an simple c++ Programme to Directly run the script and Hide the scar window, but still show the Form Window. Than im putting it all together in a Winrar SFX archive and Change some settings to temporarily safe it and open the script after Opening the SFX file.

Requirements:
  • Scar
  • A Script (optional: that generates a Form)
  • C Compiler (I'm, using Dev-C++)
  • Winrar

1. Create a script (Optional with Form).. I'll explain you how to make only your Form show up, not scar, anyways… you don't need to create a form..

2. Create a clean copy of your scar Folder, with only the Include Files you will need.

3. Copy your Clean Scar to C:\CleanScar\ .. like this:

4. Copy the script you want to make standalone to C:\CleanScar\Scar\(yourscript.scar).

5. Create the following programme in C++.. I commented it alot, so you can understand what it does ;).

//Include files for the required functions..
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <iostream>
#include <stdlib.h>

int main() {
HWND scar, script;


HWND hWnd = GetConsoleWindow(); //searches for the console Window
ShowWindow( hWnd, SW_HIDE ); //hides the console Window

popen("Scar\\scar.exe -open yourscript.scar -run", "r"); //This Opens scar and runs your script


//Waiting for your script to be run
while(FindWindow(NULL, "I am a Window") == FALSE) {
Sleep(2);
}

//Putting the window Handles in Vars
scar = FindWindow(NULL, "SCAR divi CDE");

//Fill in your WIndow Caption at "I am a Window"
//Search for "[B]frmDesign.Caption[/B]"( := 'I am a Window';) in scar
script = FindWindow(NULL, "I am a Window");

//Hiding scar and showing the Form Window
ShowWindow(scar,SW_MINIMIZE);
ShowWindow(scar,SW_HIDE);
ShowWindow(script,SW_SHOWNORMAL);

//EDIT: Its better to make the form window show up in the foreground, or it might be hidden behind Windows Folder or something ;)
SetForegroundWindow(script);

//Waiting for the Form window to dissappear
while(FindWindow(NULL, "I am a Window")) {
Sleep(2);
}

//Killing scar, when Form window is closed
system("taskkill /f /im scar.exe");


return 0;
}


6. Move your compiled .exe File to: C:\CleanScar\(YourExe.exe).

Congratulations, you'r nearly done :D…
You can test your progress now, by launching your compiled .exe. And you will only get your Form-Window:

7. Now we're doing some magic, to Create Only One .exe File… ( We could do that solely with some functions of c++, but that would kill the frame of this tutorial : 'D )
Mark Your.exe File and Your Scar Folder, Right Click and Choose: Add to archive


8. Setting Up Archive Options…

8.1
On "General". Select:
- Create SFX archive

8.2
Click on "Advanced".
- Click on the "SFX options…" Button.

8.3
On "General".
- Goto "Run after extraction, and type in the name of your .exe File

8.4
On Modes Select:
- Unpack to temporary folder
- Silent Mode: Hide all

8.4 a)
Now you may also want to add another Icon for your Standalone programme. You can do that via the "Text and Icon Options"….

8.5
- Click OK
- Click OK

Winrar will now Create The customized SFX archive…

And there you go, I even customized the icon ;) :


Conclusion:
So, since the script waits for the window handle of your form, the scar window will be visible for some milliseconds. I dont think thats annoying. But if you know a way to prevent that, feel free to tell me : 'D…
Anyways Comments and Feedback is welcome.

~caused

ShowerThoughts

2009-06-28 23:25:36

Interesting Sythe also made something like this? If I recall correctly?

ian.

2009-06-28 23:26:30

Yes, he did.

ZaSz

2009-06-28 23:27:26

Holy ****, nice. Will be using for when I sell scripts :)

Da 0wner

2009-06-28 23:28:30

Wouldn't you need to change
script = FindWindow(NULL, "I am a Window");
?

Cazax

2009-06-28 23:29:24

Wonderful :) Do you know how to do this in Delphi?

caused

2009-06-28 23:41:24

Thanks everyone ! :'D.

0wner: No, why ? ;D. It's just getting the window handle of your form.

Cazax: Why would you want to do that with delphi ? ;). C Scripts run faster =). Im sure that delphi can gather window handles as well though..

~caused

Da 0wner

2009-06-28 23:42:52

What if your form has a different title though..?

ian.

2009-06-28 23:43:04

He wants to know if you can do it with Delphi so this could be a plugin, I believe.

Edit: caused, go here ;D

ShowerThoughts

2009-06-28 23:46:10

From: Da 0wner
What if your form has a different title though..?


The form will not be called, because it will close itself. ;)
You don't need it. Scar title is static.

caused

2009-06-28 23:48:48

From: Da 0wner
What if your form has a different title though..?


right… :x.. eww.. maybe i should mention this.
Thought this was obvious =)…

Hermen: He's talking about the title of the form, also called "caption" in scar.


// Ill add that to the tutorial in a second.

Da 0wner

2009-06-28 23:50:22

Okay then, whatever :p.

caused

2009-06-28 23:54:18

I added another comment for the window caption of the form :O.

noidea

2009-06-28 23:54:29

Does this support SMART?

ZaSz

2009-06-28 23:55:37

From: noidea
Does this support SMART?


Sure does :)

caused

2009-06-29 00:06:10

From: Zasz
Sure does :)


yeah =)… Theres rather a problem, if you dont wan't to use smart ;)…

added:
SetForegroundWindow(script);

ZaSz

2009-06-29 00:09:37

I would edit to get a compiler at http://www.bloodshed.net/devcpp.html for those to lazy for googling.

noidea

2009-06-29 00:12:29

From: caused
Theres rather a problem, if you dont wan't to use smart ;)…


An individual could place FindWindowBySize() in their script, if theres a problem.

caused

2009-06-29 00:23:14

From: noidea
An individual could place FindWindowBySize() in their script, if theres a problem.


Checked that out =).
Could definately work…

You would then just need something to direct the input to the client =)

~caused

Da 0wner

2009-06-29 00:30:26

 SetClientWindowHandle
?

ZaSz

2009-06-29 00:43:13

Fixed link to img is still below for others.

[link]http://img291.imageshack.us/img291/3871/myproblem.jpg[/link]

It won't run when I run and compile. The FileName.scar is the same as in folder (I blocked it out, but it is). But It won't load scar or anything.

caused

2009-06-29 00:46:40

Make sure, you have your c++-exe file located outside the scar Folder:

Like here:
http://666kb.com/i/ba71l4pmslwkmwm8w.gif

ZaSz

2009-06-29 01:03:51

Ok, new problem, it opens up scar. When the form loads, it hides everything… And scar's still open in task mananger.

I made the form the I am a Window string.

caused

2009-06-29 01:07:29

Scar needs to be running in order for the script to run.
The C++ Programme will kill scar, after you close the form window.

Thats what this part is doing:

//Waiting for the Form window to dissappear
while(FindWindow(NULL, "I am a Window")) {
Sleep(2);
}

//Killing scar, when Form window is closed
system("taskkill /f /im scar.exe");

ZaSz

2009-06-29 01:14:15

No, scar is still running… It wont pop up the form..

As a test to see what the issue is. I put a wait before the form popup. Scar stayed open till it called the form. Then it disappeared, I looked at task manager and Scar.exe, was still running though.

caused

2009-06-29 01:17:14

Make sure, your using the right Window Caption.

here:

script = FindWindow(NULL, "I am a Window");

and here:

while(FindWindow(NULL, "I am a Window")) {...

ZaSz

2009-06-29 01:19:39

Heres my script im testing with…

I only edited the filename in C++ nothing else.

caused

2009-06-29 01:28:15

From: Zasz
Heres my script im testing with…

I only edited the filename in C++ nothing else.


tested it.. Working fine…

You'r on vista right ?. I'm using windows XP. Maybe Vista handles the window different, i couldnt evaluate that though…

Or .. your doing something wrong with the c++ script x 'DD…

~caused

//Heres the executeable:
http://uploaded.to/file/f325vs

caused

2009-06-29 01:40:01

Haha, than, nvm, i guess :)

ZaSz

2009-06-29 01:40:37

edit: ^ I mean at the bottom of screen that shows windows open/minimized.


Deleted other so I could bump..


It did work 0.- Had to many windows open. And Form didn't show on bottom bar cause its vista…

But, how do I make it go to the front of all windows????

bullzeye95

2009-06-29 01:41:49

From: Cazax
Wonderful :) Do you know how to do this in Delphi?


I attached an example. I compressed Fawki's old RatZ script with zlib (so you'll need that if you want to compile the program), and included it in the exe as a resource. It's not really a working program, but it shows how you'd go about doing it in Delphi.

I forgot to make sure the script actually ran before I compressed it, so the script will attempt to run, but will give an error.

caused

2009-06-29 01:42:00

From: Zasz
edit: ^ I mean at the bottom of screen that shows windows open.


Deleted other so I could bump..


It did work 0.- Had to many windows open. And Form didn't show on bottom bar cause its vista…

But, how do I make it go to the front of all windows????


I edited the Code with "SetForegroundWindow(script);" to do that.

ZaSz

2009-06-29 01:46:25

From: caused
I edited the Code with "SetForegroundWindow(script);" to do that.


Doesn't work in vista I guess, cause its behind all windows.

caused

2009-06-29 01:56:16

From: Zasz
Doesn't work in vista I guess, cause its behind all windows.


Hmn,, i dont got Vista, so i couldnt test anything..

Maybe try some madness, like:


while (GetActiveWindow() != script){
ShowWindow(script,SW_SHOWNORMAL);
SetForegroundWindow(script);
SetActiveWindow(script);
Sleep(5);
}

ZaSz

2009-06-29 02:02:48

Didn't work, but thats o.k, I am thinking we could make it so we could make a players.txt file that be put in a folder with the .exe. So we could have people fill out declare players from there.

Cazax

2009-06-29 02:09:08

From: bullzeye95
I attached an example. I compressed Fawki's old RatZ script with zlib (so you'll need that if you want to compile the program), and included it in the exe as a resource. It's not really a working program, but it shows how you'd go about doing it in Delphi.

I forgot to make sure the script actually ran before I compressed it, so the script will attempt to run, but will give an error.


Thanks :) I'm saving it if I ever need to compile an script to exe.

caused

2009-06-29 02:10:17

Hmn, if only i had vista xD. I'd get it to work for you =).
I am thinking we could make it so we could make a players.txt file that be put in a folder with the .exe. So we could have people fill out declare players from there.


Or tell people to put the script on the desktop =).

//EDIT:
Did you try the file i Uploaded ?

ZaSz

2009-06-29 02:16:12

me feelz dumb. I was Compiling and running and stuff in dev-C++. When Dev was the main window. The other window wouldnt be called first. But I tried the .exe I made and it worked.

caused

2009-06-29 02:20:13

From: Zasz
me feelz dumb. I was Compiling and running and stuff in dev-C++. When Dev was the main window. The other window wouldnt be called first. But I tried the .exe I made and it worked.


haha, gz ;)

ZaSz

2009-06-29 02:36:36

SetupSrl doesn't work, it freezes the script.

Any suggestions? (sorry for being a bother :))

Captions Me, but I edited the C++ to work with that.

caused

2009-06-29 02:49:18

It's freezing the window ?. Or does the whole script freeze ?

If the window freezes, it might be because, you need to change your way to write your script ;).. Cause with my current code(c++), the window has to be open all the time.

~caused

ZaSz

2009-06-29 02:50:45

I keep the window open. The whole script freezes.

caused

2009-06-29 02:56:18

From: Zasz
I keep the window open. The whole script freezes.


I guess it's just the window. Don't got time to check it out now though :x…

I'll try it later or tommorow, if you havnt found a sollution until than =)..

~caused

noidea

2009-07-01 09:03:14

Hmm. My problem:
I click Main.exe, and it opens SCAR and runs it.
I dont the the "I r w1ndow" stuff.

ZaSz

2009-07-01 10:07:14

From: noidea
Hmm. My problem:
I click Main.exe, and it opens SCAR and runs it.
I dont the the "I r w1ndow" stuff.


You have to make the form. So it will hide scar when form pops up. So you have to base your script off the form. When the form closes, so will your script.

Right now, im working on an alternitive to this though.

caused

2009-07-01 20:32:23

From: ZaSz
You have to make the form. So it will hide scar when form pops up. So you have to base your script off the form. When the form closes, so will your script.

Right now, im working on an alternitive to this though.


A Simple alternative would be to change the Scar Handle, when the Script finishes =).

Or you create an extra window like sythe, with control elements for your script (start stop).

~caused

Ouivile

2009-07-27 08:25:30

wait, is it actually stand alone?!!?!? like u can take the exe all by iteself and run it on another pc? or do u need its library with it? like is the exe just a 1 click run instead of opening scar pressing play and using more resources?!?!?!?!

because if this is completly standalone im verrrryyyy interested!!!!

ian.

2009-07-27 08:43:03

From: Ouivile
wait, is it actually stand alone?!!?!? like u can take the exe all by iteself and run it on another pc? or do u need its library with it? like is the exe just a 1 click run instead of opening scar pressing play and using more resources?!?!?!?!

because if this is completly standalone im verrrryyyy interested!!!!


What I would do is just add the SRL functions you need/use to the script. It'd be bigger, but it would be completely stand alone.

Ouivile

2009-07-29 22:18:53

oh i see, so any srl functions should be added in the actual script and all original scar functions can stay and then its completly standalone?!?

edit would this work with smart?

caused

2009-08-23 03:34:12

Yes, Ouvile.

I'd suggest to just try it out ;P.

~caused

tom99

2009-12-07 04:11:24

This worked well, thank you for your genius tut, i was first trying to compile this with visual express 2008, that ddidnt work but dev-c++ did the trick, however it install scar and run the script but it does not hide the window once the script is runned, why is that, i woud like make some scripts to a freind of my without that he send it to everyone, so how can you in c++ hide the window after the script is runned? was it supose to do so?

caused

2010-01-08 19:29:24

From: tom99
This worked well, thank you for your genius tut, i was first trying to compile this with visual express 2008, that ddidnt work but dev-c++ did the trick, however it install scar and run the script but it does not hide the window once the script is runned, why is that, i woud like make some scripts to a freind of my without that he send it to everyone, so how can you in c++ hide the window after the script is runned? was it supose to do so?


  //Waiting for the Form window to dissappear
while(FindWindow(NULL, "I am a Window")) {
Sleep(2);
}

//Killing scar, when Form window is closed
system("taskkill /f /im scar.exe");

It's all in the tutorial ;)

gerauchert

2010-01-08 20:21:47

From: caused
  //Waiting for the Form window to dissappear
while(FindWindow(NULL, "I am a Window")) {
Sleep(2);
}

//Killing scar, when Form window is closed
system("taskkill /f /im scar.exe");

It's all in the tutorial ;)


Still can't get the process to end or SCAR to close :(

It isn't setting the form to the foreground either… what am I screwing up lol?


//Include files for the required functions..
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <iostream>
#include <stdlib.h>

int main() {
HWND scar, script;


HWND hWnd = GetConsoleWindow(); //searches for the console Window
ShowWindow( hWnd, SW_HIDE ); //hides the console Window

popen("Scar\\scar.exe -open test.scar -run", "r"); //This Opens scar and runs your script


//Waiting for your script to be run
while(FindWindow(NULL, "I am a Window") == FALSE) {
Sleep(2);
}

//Putting the window Handles in Vars
scar = FindWindow(NULL, "SCAR");

//Fill in your WIndow Caption at "I am a Window"
//Search for "frmDesign.Caption"( := 'I am a Window';) in scar
script = FindWindow(NULL, "Pure Simplicity");

//Hiding scar and showing the Form Window
ShowWindow(scar,SW_MINIMIZE);
ShowWindow(scar,SW_HIDE);
ShowWindow(script,SW_SHOWNORMAL);

//EDIT: Its better to make the form window show up in the foreground, or it might be hidden behind Windows Folder or something ;)
SetForegroundWindow(script);

//Waiting for the Form window to dissappear
while(FindWindow(NULL, "Pure Simplicity")) {
Sleep(2);
}

//Killing scar, when Form window is closed
system("taskkill /f /im scar.exe");


return 0;
}

EDIT: Nevermind. I figured it out… you have to type out the EXACT caption displayed on scar. I did notice that SCAR didn't hide or minimize though… Solved with MoveToTray in SCAR.

caused

2010-01-11 14:08:37

Well, taskkill should work :X.. at least with windows XP. maybe they changed it for Win7 or Vista I dunno, check out the taskkill /? command, and the name of the process (use cmd -> tasklist).

Good luck.

~caused

Baked0420

2010-01-11 14:38:38

wow nice, really cool. So you can have friends run scripts with this without them ever downloading SCAR? That's what it seems like, if so I'll be writing and showing lots more scripts to people :p

Bad Boy JH

2010-08-17 22:06:15

Sorry for gravedig, but does anyone know if this still works? I would love to be able to show my software teacher my program as an .exe rather than as a script…

i luffs yeww

2010-08-18 02:46:04

:) You could try and find out.

D4rk Gr4y

2010-08-18 03:02:50

Yes this still should work, but you should know that Simba does/will have the capabilities to make scripts standalone .exes. the real gravedigger of this was "caused" lol. 1 year difference as apposed to your 7 month lol. Don't worry, I was interested in this too.

i luffs yeww

2010-08-18 03:06:20

You can't grave dig tutorials.

D4rk Gr4y

2010-08-18 06:04:46

I think all rules are made with relevance. As in, grave digging isn't allowed when something is irrelevant. This however, has relevance to current events and is a legitimate question to be asked. I suppose he could have made his own thread about it, asking how to make .scar or .simba into .exes. but then a lot of people would have just said search for it or flame in other ways…

@oh and btw Bad Boy when i said this should still work i meant with scar. as in not with SMART. just scar. i dont think you can use C++ to compile java plugins from pascal. but then again…im not sure lol.

i luffs yeww

2010-08-18 12:37:06

No, you just can't grave dig tutorials. No matter how old or "useless."

Kave

2010-09-21 11:47:23

Have the script working on my actual pc but when I try run it on another pc I get an error saying "file new.scar is not found"

any ideas?

http://i55.tinypic.com/8x29zr.png

new.scar is in C:\CleanScar\Scar

and popen("Scar\\scar.exe -open new.scar -run", "r"); //This Opens scar and runs your script

Shuttleu

2010-09-21 11:54:33

From: Kave
Have the script working on my actual pc but when I try run it on another pc I get an error saying "file new.scar is not found"

any ideas?

http://i55.tinypic.com/8x29zr.png

new.scar is in C:\CleanScar\Scar

and popen("Scar\\scar.exe -open new.scar -run", "r"); //This Opens scar and runs your script


wow, tiny resolution, but i thought the script goes inside the EXE?

~shut

Kave

2010-09-22 14:13:32

Any ideas guys? Really need this ;_;

weequ

2010-09-22 16:36:55

Now I'm interested in this too. (Didn't notice this thread before)

Kave

2010-09-22 17:04:23

I've fixed that said problem somehow not even sure how lol. (got it to work on my vmware)

Freddy1990

2010-09-28 14:32:59

From: Kave
I've fixed that said problem somehow not even sure how lol. (got it to work on my vmware)


You could always try with the SCAR 3.25 Beta, it has a new commandline argument processor embedded that works a lot smoother. It supports all of the old arguments, but it's a lot more flexible at the same time. It will basically run the last script you tell it to open. -open isn't even a requirement anymore, but still possible.

Naike

2010-09-28 16:50:21

From: Freddy1990
You could always try with the SCAR 3.25 Beta, it has a new commandline argument processor embedded that works a lot smoother. It supports all of the old arguments, but it's a lot more flexible at the same time. It will basically run the last script you tell it to open. -open isn't even a requirement anymore, but still possible.


Would be really neat if you did a in-built function for converting it to a .exe :bart: