Solved

PHP and VBS

Posted on 2011-03-01
5
806 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
[X]
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
  • 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

Title # Comments Views Activity
embadded search engine in website 4 46
Why am I getting SyntaxError: missing ; before statement error 39 79
Code not executing correctly. 3 43
php time 12 25
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

732 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