using Windows Script Host from PureBasic

Just starting out? Need help? Post your questions and find answers here.
^OO^
User
User
Posts: 27
Joined: Mon Apr 28, 2003 5:58 am
Location: United Kingdom
Contact:

using Windows Script Host from PureBasic

Post by ^OO^ »

8) Hello all

Can anyone show me how to get PureBasic to call wscript.exe and return a result?

Reason:
wscript.exe has a very good built in parser and I would like to get it to parse math calculations.
Normally, it returns results via an alert windows.
No good for my purpose.
Is it possible to get PureBasic to call wscript.exe with a task and collect the result?

8) Thanks in advance
BF 1942, BF Desert Combat, BF The Road To Rome, BF Secret Weapons, BF Vietnam.
Half-Life - The Awakening.
UT1998, UT2003, UT2004.
X2 - The Threat.
Far Cry.
Jose
User
User
Posts: 34
Joined: Sat Apr 26, 2003 9:20 pm

Post by Jose »

Hi Julian,

Using CScript instead of wscript exposes the write-only output stream, you can then send this output to a file like this;

"CScript test.vbs >test.txt"

Use PB to run your sript then read the results from the file.

Hope that helps.
Jose
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Re: using Windows Script Host from PureBasic

Post by ricardo »

^OO^ wrote:8) Hello all

Can anyone show me how to get PureBasic to call wscript.exe and return a result?

Reason:
wscript.exe has a very good built in parser and I would like to get it to parse math calculations.
Normally, it returns results via an alert windows.
No good for my purpose.
Is it possible to get PureBasic to call wscript.exe with a task and collect the result?

8) Thanks in advance
Hi ^OO^ (how did you pronounce that? he he)

There is a way to CallCOM from PureBasic and there you can REALLY get access to wsh (vbs, js, etc).
The problem is that its difficult, but some people here (Danilo, El_Choni) may know how to do it.

I was hoping that someday Danilo release some shareware tool that help us to call Com from PB, i think it could be a great tool!
ARGENTINA WORLD CHAMPION
^OO^
User
User
Posts: 27
Joined: Mon Apr 28, 2003 5:58 am
Location: United Kingdom
Contact:

Post by ^OO^ »

8) Hi Ricardo, Jose

It seems then, that I must persevere with rolling my own parser.
I am finding that it's much harder than it first seems.

It should really be in PB as a standard command: n.f=parse(expression$)

Since PB is already equipped with a parser to interpret what programmers have written, it should not be too difficult to make it into a command.

With whom should I plead?
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

> Since PB is already equipped with a parser to interpret what
> programmers have written, it should not be too difficult to make it into
> a command.

This would mean, that a big part of the compiler's code must be put in
every executable. That would bloat it, i think.

Timo
quidquid Latine dictum sit altum videtur
ebs
Enthusiast
Enthusiast
Posts: 557
Joined: Fri Apr 25, 2003 11:08 pm

Post by ebs »

Julian/^OO^,

If you can translate it, this post from the German forum gives you a DLL that does math parsing:

http://www.robsite.de/php/pureboard/viewtopic.php?t=130

The download address for the DLL is :

http://www.adventuretipps.de/purebasic/fmlcalc.zip

HTH,
Eric
^OO^
User
User
Posts: 27
Joined: Mon Apr 28, 2003 5:58 am
Location: United Kingdom
Contact:

Post by ^OO^ »

Hi Freak,

A good parser might be a bit bulky but everything is getting bigger anyway.
Sacrificing useful functions to make the code smaller seems inappropriate,
somehow. The whole idea of Basic is to make everything easy for
programmers. If you decide that programmers should be denied facilities
on the grounds that they are bulky, where do you stop? There are probably
other bits of PureBasic which you might consider bulky. Would you like to
go through it all, cutting out anything you don't think is important for your
own projects? For my purposes, collecting, interpreting and utilizing user
input happens to be high on my list of priorities and not having a decent
parser is crippling. It is true that hardly any versions of Basic include a
parser; the usual offering is some equivalent of ValF() which does nothing
but convert a numeric string to a value. It cannot cope with any math
whatsoever. The only Basic that I know for sure has a proper parser is BBC
Basic as found on the Acorn BBC Micro and subsequent Acorn machines.

Adding a parser to PureBasic would make PureBasic uniquely useful and
would be a good reason for more people to choose it as their priority
desktop programming language. Visual Basic does not have a parser which
is strange as Windows Script Host has a really good one; a near miss!
Delphi, sadly, also lacks one.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Hi Ebs,

I am familiar with Sebi's fmlcalc.DLL. I struggled with it for a bit until I
realized that it does not incorporate common functions like sin(), cos(),
tan(), etc. They can be added but not by their proper names. I wound up
with msin(), mcos(), mtan(), etc. This would not be appropriate for a user's
desktop calculator. Another near miss [sigh].

You would not think that writing a parser would be so tricky.
I have got it working with simple operators and am now tackling brackets.
Oh my poor little brain.

I thought that searching for a parser would be easier than writing one.
I was right - searching for one IS easier. Finding one has proven harder.
If I live long enough to solve brackets, there are still the functions and the
user-defined variables to do. I will be very old by then.
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post by ricardo »

^OO^

But the WSH offers more than just a parser, offers an easy way to do MANY things in windows that its impossible now in PB.
In fact, if we resolve how to manage WSH then all the CallCOM are resolved, because calling it from WSH its easy.

Per example, many ppl here want to have more control on webgadget, well by WSH its easy to control every aspect of it.

I hope that Fred decide to give us a way to have full access to WSH.
From there you can control every little thing of windows easily.

Sooner or later PB will have to incorporate a complete COM stuff sincede there is no other way to do many things in windows.
ARGENTINA WORLD CHAMPION
^OO^
User
User
Posts: 27
Joined: Mon Apr 28, 2003 5:58 am
Location: United Kingdom
Contact:

Post by ^OO^ »

Hi Ricardo,

> I hope that Fred decides to give us a way to have full access to WSH.
> From there you can control every little thing of windows easily.

I hope so too.
We can only hope that Fred does this.
There have been no promises, yet.

Meanwhile - Do you know how to write a parser?

;-) ^0=^
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post by ricardo »

One idea:

Maybe outthere is some dll that let us call wsh, something like a wsh wrapper. Did anybody knows if there is any wrapper?
ARGENTINA WORLD CHAMPION
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post by ricardo »

Just to make an experiment i make a VB executable that parses via wsh any code that you sent to it by the commandline form a PureBasic application.
In my example if pass this vbs code:

a = 0
b = 0
if a = 0 then
msgbox "true"
else
msgbox "false"
end if

And i pass this code (or any other) from a PureBasic application and it works perfect, the only problem is that from VB we cant make real dlls (just activex dlls) but maybe if some one help us coding this easy code in C++ or ASM to a dll we can have a nice solution.

In my example the result is by a messagebox but its not to difficult to use a procedure to get the return from vbs.

If you want to test my example, download it from

http://www.getafile.com/cgi-bin/merlot/ ... Script.zip

In fact you can send your own vbs code and it will run it fast and easy. (Even can call any Activex from it and it will work!)

The VB code is about 2 lines!!

Thats why i think that we can develope some dll in asm or c++ that is just a wrapper to run a vbs and pick the result back!!

**If you need some missing runtimes, download it from

http://www.getafile.com/cgi-bin/merlot/ ... times1.zip

Just register it!!
ARGENTINA WORLD CHAMPION
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Post by jack »

here is a link to a parser in IBasic, you should be able to translate it to PB
http://www.pyxia.com/community/viewtopi ... 19&start=0

hope it helps
^OO^
User
User
Posts: 27
Joined: Mon Apr 28, 2003 5:58 am
Location: United Kingdom
Contact:

Post by ^OO^ »

8) Hi Ricardo,

I had considered pursuing the WSH line until I considered what I was going to do to make it work in Linux.
I concluded that I need to write a parser at some point, anyway.
I guess this is the point. :?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Hi Jack

Yes, I have looked at IBasic and found that parser file :-)
I shall download it and have a go at transposing it to PureBasic.
Thanks for pointing it out :lol:

Some hours later ...

Yoweee!
I have downloaded it. I have been reading it. There is no way to directly translate it to PB.

Therefore - I have been trying to understand it. It is beyond me. :oops:

You have a go - put me to even more shame :wink:

No shortcuts this time :(
^OO^
User
User
Posts: 27
Joined: Mon Apr 28, 2003 5:58 am
Location: United Kingdom
Contact:

Post by ^OO^ »

Hi Ricardo

I have just been playing with your script thingy and it copes wonderfully with whatever I give it. :)

It would be worth taking the trouble to make the DLL wrapper if it were strictly for Windows.
I don't know how to do such a thing, though. :cry:

The application I am working on will execute 256 calculations each time Return is pressed.
How fast could WSH execute them?
I am guessing that once it was in RAM, WSH would remain there and whizz thru the lot, fast.
Is this true, do you think?
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post by ricardo »

Hi ^OO^
I have just been playing with your script thingy and it copes wonderfully with whatever I give it.
Thats why i suggest to take a look to it.
The more interesant thing is that if you send a code to run flash or msagent or to control outlook or to control IExplorer, etc, etc, etc. It will do it!!

Its the door to a very big 'layer' of windows.

With this small gizmo you have all the power of vbs on your PB application, and that good for me.

But, we need a dll made in C++ or asm to avoid runtimes.

I have VC++ and i have coded some things (not to much) but i dont have any idea how to call COM from it.

As i said, in VB it only requieres 2 or 3 lines of code, then it could not be so hard in other language.

I think it worth to make this dll.

The application I am working on will execute 256 calculations each time Return is pressed.
How fast could WSH execute them?


Very fast, once the WSH is loaded its fast to run any code.

I think that our dll must be capable to send each result to a procedure in PB (that part is easy using a pointer).

Can any body help us?

There is some source in MASM to call vbs or we can try in C++.
ARGENTINA WORLD CHAMPION
Post Reply