Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

PHP and VBS

Posted on 2011-03-01
5
802 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:Dushan De Silva
  • 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:Dushan De Silva
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:Dushan De Silva
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

856 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