Solved

PHP and VBS

Posted on 2011-03-01
5
784 Views
Last Modified: 2012-05-11
Hi Experts,
We can use PHP exec command to call VBS code.
<?
$arg = 'anything';
exec ("csript script1.vbs $arg" );
?>

1.) How can I get return values of script1.vbs to PHP.
2.) From PHP can I call fn1 function which is inside script1.vbs

BR Dushan.
0
Comment
Question by:Dushan911
  • 3
  • 2
5 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 35012578
Hi,

1)
I'm not that great with PHP, but I do know that VBScript is only capable of returning an integer value, through the use of
WScript.Quit(#)

However, it looks like you could obtain the output from the command by adding a parameter to the exec method:
http://php.net/manual/en/function.exec.php

So if your VBS had WScript.Echo statements in it, then the PHP array should hold that output.

2)
No, you cannot "include" any code in the page for global execution other than php.  If you want to use it, you'd need to convert it.

Regards,

Rob.
0
 
LVL 17

Author Comment

by:Dushan911
ID: 35012673
Hi Rob,
Thanks a lot again!
1.) Fantastic!, I will use WScript.Echo and will capture it from PHP as array.
2.) Can I call VBS function from command line. (then I can try to execute that command using php exec or shell_exec)

BR Dushan.
0
 
LVL 65

Assisted Solution

by:RobSampson
RobSampson earned 500 total points
ID: 35012908
1) Sure, hopefully it works.
2) I guess you could.  If you're VBS had something like this:

 
strFunction = WScript.Arguments.Item(0)

Execute "Call " & strFunction

Function MyFunction1
	WScript.Echo "Function1 was called."
End Function

Function MyFunction2
	WScript.Echo "Function2 was called."
End Function

Open in new window


and then you used this PHP:
$arg = 'Function1';
exec ("csript script1.vbs $arg",$arroutput,$returnvalue);

Then it should work (I think).

Regards,

Rob.
0
 
LVL 17

Author Closing Comment

by:Dushan911
ID: 35013077
Yes, thanks lot!
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 35013102
No worries.

Thanks for the grade,

Regards,

Rob.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now