PDA

View Full Version : How To Make Any Scar Script A Standalone.exe



caused
06-29-2009, 03:22 AM
(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:
http://666kb.com/i/ba716ab9m9e59bf6o.bmp

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 "frmDesign.Caption"( := '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:
http://666kb.com/i/ba71l4pmslwkmwm8w.gif

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

http://666kb.com/i/ba71nia638p8av3q8.jpg

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 ;) :

http://666kb.com/i/ba72atb757jhfcfxc.gif

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
06-29-2009, 03:25 AM
Interesting Sythe also made something like this? If I recall correctly?

ian.
06-29-2009, 03:26 AM
Yes, he did.

ZaSz
06-29-2009, 03:27 AM
Holy ****, nice. Will be using for when I sell scripts :)

Da 0wner
06-29-2009, 03:28 AM
Wouldn't you need to change
script = FindWindow(NULL, "I am a Window");
?

Cazax
06-29-2009, 03:29 AM
Wonderful :) Do you know how to do this in Delphi?

caused
06-29-2009, 03:41 AM
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
06-29-2009, 03:42 AM
What if your form has a different title though..?

ian.
06-29-2009, 03:43 AM
He wants to know if you can do it with Delphi so this could be a plugin, I believe.

Edit: caused, go here (http://www.villavu.com/forum/showpost.php?p=593273&postcount=46) ;D

ShowerThoughts
06-29-2009, 03:46 AM
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
06-29-2009, 03:48 AM
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
06-29-2009, 03:50 AM
Okay then, whatever :p.

caused
06-29-2009, 03:54 AM
I added another comment for the window caption of the form :O.

noidea
06-29-2009, 03:54 AM
Does this support SMART?

ZaSz
06-29-2009, 03:55 AM
Does this support SMART?

Sure does :)

caused
06-29-2009, 04:06 AM
Sure does :)

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

added:
SetForegroundWindow(script);

ZaSz
06-29-2009, 04:09 AM
I would edit to get a compiler at http://www.bloodshed.net/devcpp.html for those to lazy for googling.

noidea
06-29-2009, 04:12 AM
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
06-29-2009, 04:23 AM
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
06-29-2009, 04:30 AM
SetClientWindowHandle?

ZaSz
06-29-2009, 04:43 AM
Fixed link to img is still below for others.

http://img291.imageshack.us/img291/3871/myproblem.jpg

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
06-29-2009, 04:46 AM
Make sure, you have your c++-exe file located outside the scar Folder:

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

ZaSz
06-29-2009, 05:03 AM
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
06-29-2009, 05:07 AM
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
06-29-2009, 05:14 AM
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
06-29-2009, 05:17 AM
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
06-29-2009, 05:19 AM
Heres my script im testing with...

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

caused
06-29-2009, 05:28 AM
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
06-29-2009, 05:40 AM
Haha, than, nvm, i guess :)

ZaSz
06-29-2009, 05:40 AM
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
06-29-2009, 05:41 AM
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
06-29-2009, 05:42 AM
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
06-29-2009, 05:46 AM
I edited the Code with "SetForegroundWindow(script);" to do that.

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

caused
06-29-2009, 05:56 AM
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
06-29-2009, 06:02 AM
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
06-29-2009, 06:09 AM
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
06-29-2009, 06:10 AM
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
06-29-2009, 06:16 AM
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
06-29-2009, 06:20 AM
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
06-29-2009, 06:36 AM
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
06-29-2009, 06:49 AM
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
06-29-2009, 06:50 AM
I keep the window open. The whole script freezes.

caused
06-29-2009, 06:56 AM
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
07-01-2009, 01:03 PM
Hmm. My problem:
I click Main.exe, and it opens SCAR and runs it.
I dont the the "I r w1ndow" stuff.

ZaSz
07-01-2009, 02:07 PM
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
07-02-2009, 12:32 AM
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
07-27-2009, 12:25 PM
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.
07-27-2009, 12:43 PM
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
07-30-2009, 02:18 AM
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
08-23-2009, 07:34 AM
Yes, Ouvile.

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

~caused

tom99
12-07-2009, 09:11 AM
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
01-09-2010, 12:29 AM
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
01-09-2010, 01:21 AM
//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
01-11-2010, 07:08 PM
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
01-11-2010, 07:38 PM
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
08-18-2010, 02:06 AM
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
08-18-2010, 06:46 AM
:) You could try and find out.

D4rk Gr4y
08-18-2010, 07:02 AM
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
08-18-2010, 07:06 AM
You can't grave dig tutorials.

D4rk Gr4y
08-18-2010, 10:04 AM
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
08-18-2010, 04:37 PM
No, you just can't grave dig tutorials. No matter how old or "useless."

Kave
09-21-2010, 03:47 PM
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
09-21-2010, 03:54 PM
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
09-22-2010, 06:13 PM
Any ideas guys? Really need this ;_;

weequ
09-22-2010, 08:36 PM
Now I'm interested in this too. (Didn't notice this thread before)

Kave
09-22-2010, 09:04 PM
I've fixed that said problem somehow not even sure how lol. (got it to work on my vmware)

Freddy1990
09-28-2010, 06:32 PM
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
09-28-2010, 08:50 PM
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: