ActiveXPosh in Jscript

This forum can be browsed by the general public. Posting is no longer allowed as the product has been discontinued.
This topic is 15 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
ddehouwer
Posts: 3
Last visit: Sun Dec 07, 2008 3:46 pm

ActiveXPosh in Jscript

Post by ddehouwer »

Hello there

I was looking for a way today to incorporate Powershell scripts or code into Jscripts. This way I found ActiveXPosh which can do great things. I found numerous examples on the web and on your support forums how to do things in VBScript altho not a single one on JScript. Our company however prefers JScript over VBScript. I did take your sample code and tried to transfer it to JScript the way I think is correct.

VBScript:
VBScript Code
Double-click the code block to select all.
Set ActiveXPosh = CreateObject("SAPIEN.ActiveXPoSH")
    
    if ActiveXPosh.Eval("get-process winword") = vbtrue Then
       WScript.Echo "Microsoft Word is running"
    Else
       WScript.Echo "Microsoft Word is not running"
    End if

JScript:

Code: Select all

ActiveXPosh = WScript.CreateObject("SAPIEN.ActiveXPosh");

if (ActiveXPosh.Eval("get-process winword") == true)
{
 WScript.Echo("Microsoft Word is running");
else
 WScript.Echo("Microsoft Word is not running");
}

However running this gives me a syntax error. Do you have any samples of incorporating ActiveXPosh in Jscript or can you direct me in the right direction what's wrong in this very basic script?
User avatar
jhicks
Posts: 1789
Last visit: Mon Oct 19, 2015 9:21 am

ActiveXPosh in Jscript

Post by jhicks »

Your VBS example shouldn't have worked either. You need to call the Init method.here's JScript code that works for me:ActiveXPosh = WScript.CreateObject("SAPIEN.ActiveXPosh");ActiveXPosh.Init("True");if (ActiveXPosh.Eval("get-process winword") == true){ WScript.Echo("Microsoft Word is running")}; else { WScript.Echo("Microsoft Word is not running");}
User avatar
ddehouwer
Posts: 3
Last visit: Sun Dec 07, 2008 3:46 pm

ActiveXPosh in Jscript

Post by ddehouwer »

Strangely enough that doesn't work for me either. Using the exact same script in your above example I get the following errorcode:

Code: Select all

Error: Automatisation isn't supported by this class
       
Code: 800A01AE
If I remove the Init line the script doesn't give an error but the result is always that word isn't running even if it indeed is. I tried this as well with other processes but everytime you get the answer that the process isn't running.

On the other hand, I copied the example in the pdf you provided and made it a vbs file and I get the same result so I'm guessing there's maybe something wrong with my configuration. I installed the ActiveXPosh setup and I have Powershell 1.0 running on a Vista machine.
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

ActiveXPosh in Jscript

Post by Alexander Riedel »

If you remove the call to Init, the PowerShell is not instantiated. So nothing would work really.

The correct code is:ActiveXPosh = WScript.CreateObject("SAPIEN.ActiveXPosh");ActiveXPosh.Init(true);
if (ActiveXPosh.Eval("get-process winword") == true) { WScript.Echo("Microsoft Word is running")}else { WScript.Echo("Microsoft Word is not running");}
Note that the parameter to init is a number,
indicating whether the profiles should be executed or not.

Alex
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 15 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.