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.
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
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?
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");}
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.
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.
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.